Skip to content

Commit

Permalink
CXP-3424: Use default CDC index for SqlServer Connector
Browse files Browse the repository at this point in the history
Adding `__$command_id ASC` to the order clause of the query allows
for the usage of the clustered index.
  • Loading branch information
ramanenka committed Jan 22, 2025
1 parent f823438 commit 00b416a
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public class SqlServerConnection extends JdbcConnection {
+ LSN_TIMESTAMP_SELECT_STATEMENT;
private static final String GET_ALL_CHANGES_FOR_TABLE_FROM_FUNCTION = "FROM [#db].cdc.[fn_cdc_get_all_changes_#table](?, ?, N'all update old')";
private static final String GET_ALL_CHANGES_FOR_TABLE_FROM_DIRECT = "FROM [#db].cdc.[#table]";
private static final String GET_ALL_CHANGES_FOR_TABLE_ORDER_BY = "ORDER BY [__$start_lsn] ASC, [__$seqval] ASC, [__$operation] ASC";
private static final String GET_ALL_CHANGES_FOR_TABLE_FROM_FUNCTION_ORDER_BY = "ORDER BY [__$start_lsn] ASC, [__$seqval] ASC, [__$operation] ASC";
private static final String GET_ALL_CHANGES_FOR_TABLE_FROM_DIRECT_ORDER_BY = "ORDER BY [__$start_lsn] ASC, [__$command_id] ASC, [__$seqval] ASC, [__$operation] ASC";

/**
* Queries the list of captured column names and their change table identifiers in the given database.
Expand Down Expand Up @@ -212,7 +213,14 @@ private String buildGetAllChangesForTableQuery(SqlServerConnectorConfig.DataQuer
result += " WHERE " + String.join(" AND ", where) + " ";
}

result += GET_ALL_CHANGES_FOR_TABLE_ORDER_BY;
switch (dataQueryMode) {
case FUNCTION:
result += GET_ALL_CHANGES_FOR_TABLE_FROM_FUNCTION_ORDER_BY;
break;
case DIRECT:
result += GET_ALL_CHANGES_FOR_TABLE_FROM_DIRECT_ORDER_BY;
break;
}

return result;
}
Expand Down

0 comments on commit 00b416a

Please sign in to comment.