Skip to content

Commit a2a76ba

Browse files
author
Nicolas Maquet
committed
order boostrap select * by pk when available
1 parent 58da662 commit a2a76ba

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/com/zendesk/maxwell/bootstrap/SynchronousBootstrapper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void startBootstrap(RowMap startBootstrapRow, Schema schema, AbstractProd
6868
LOGGER.info(String.format("bootstrapping started for %s.%s, binlog position is %s", databaseName, tableName, position.toString()));
6969
try ( Connection connection = getConnection() ) {
7070
setBootstrapRowToStarted(startBootstrapRow, connection);
71-
ResultSet resultSet = getAllRows(databaseName, tableName, connection);
71+
ResultSet resultSet = getAllRows(databaseName, tableName, schema, connection);
7272
int insertedRows = 0;
7373
while ( resultSet.next() ) {
7474
RowMap row = new RowMap(
@@ -165,9 +165,14 @@ private void ensureTable(String tableName, Database database) {
165165
findTable(tableName, database);
166166
}
167167

168-
private ResultSet getAllRows(String databaseName, String tableName, Connection connection) throws SQLException, InterruptedException {
168+
private ResultSet getAllRows(String databaseName, String tableName, Schema schema, Connection connection) throws SQLException, InterruptedException {
169169
Statement statement = createBatchStatement(connection);
170-
return statement.executeQuery(String.format("select * from %s.%s", databaseName, tableName));
170+
String pk = schema.findDatabase(databaseName).findTable(tableName).getPKString();
171+
if ( pk != null ) {
172+
return statement.executeQuery(String.format("select * from %s.%s order by %s", databaseName, tableName, pk));
173+
} else {
174+
return statement.executeQuery(String.format("select * from %s.%s", databaseName, tableName));
175+
}
171176
}
172177

173178
private Statement createBatchStatement(Connection connection) throws SQLException, InterruptedException {

0 commit comments

Comments
 (0)