hoorf opened a new issue #12008:
URL: https://github.com/apache/shardingsphere/issues/12008
this find pk range method will invoke many times for
```
@Override
public String buildSplitByPrimaryKeyRangeSQL(final String tableName,
final String primaryKey) {
return String.format("SELECT MAX(%s) FROM (SELECT %s FROM %s WHERE
%s>=? limit ?) t", quote(primaryKey), quote(primaryKey), quote(tableName),
quote(primaryKey));
}
```
use in
```
private Collection<ScalingPosition<?>> getPositionByPrimaryKeyRange(final
JobContext jobContext, final DataSource dataSource, final
InventoryDumperConfiguration dumperConfig) {
Collection<ScalingPosition<?>> result = new ArrayList<>();
String sql =
ScalingSQLBuilderFactory.newInstance(jobContext.getJobConfig().getHandleConfig().getDatabaseType())
.buildSplitByPrimaryKeyRangeSQL(dumperConfig.getTableName(),
dumperConfig.getPrimaryKey());
try (Connection connection = dataSource.getConnection();
PreparedStatement ps = connection.prepareStatement(sql)) {
long beginId = 0;
for (int i = 0; i < Integer.MAX_VALUE; i++) {
ps.setLong(1, beginId);
ps.setLong(2,
jobContext.getJobConfig().getHandleConfig().getShardingSize());
try (ResultSet rs = ps.executeQuery()) {
rs.next();
long endId = rs.getLong(1);
if (endId == 0) {
break;
}
result.add(new PrimaryKeyPosition(beginId, endId));
beginId = endId + 1;
}
}
// fix empty table missing inventory task
if (0 == result.size()) {
result.add(new PrimaryKeyPosition(0, 0));
}
} catch (final SQLException ex) {
throw new PrepareFailedException(String.format("Split task for
table %s by primary key %s error", dumperConfig.getTableName(),
dumperConfig.getPrimaryKey()), ex);
}
return result;
}
```
the pk start from 0,if use `SnowFlake ` pk , useless invoke many times
optimize
- find `min` and `max` pk count the range
- support the pk like `O100440001` to `O100449999` string pk not int pk
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]