Skip to content

Commit

Permalink
DBZ-7351 Avoid child data snapshots from PostgreSQL parent tables
Browse files Browse the repository at this point in the history
When PostgreSQL tables are configured with inheritance (INHERIT clause),
data is streamed by Debezium from the table where the data resides
(usually the child tables).

However, during the initial/incremental snapshot, Debezium selects all
data from the parent tables, including child data, which pushes
unexpected/duplicate data into the topics (all data from child tables).

Using a "SELECT ... FROM ONLY" retrieves only data from the current
table and avoids retrieving data from child tables.

Signed-off-by: Nicolas Payart <npayart@gmail.com>
  • Loading branch information
koleo committed Jan 15, 2024
1 parent b905016 commit d60696b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void init(PostgresConnectorConfig config, OffsetState sourceInfo, SlotSta
@Override
public Optional<String> buildSnapshotQuery(TableId tableId, List<String> snapshotSelectColumns) {
String query = snapshotSelectColumns.stream()
.collect(Collectors.joining(", ", "SELECT ", " FROM " + tableId.toDoubleQuotedString()));
.collect(Collectors.joining(", ", "SELECT ", " FROM ONLY " + tableId.toDoubleQuotedString()));

return Optional.of(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Optional<String> buildSnapshotQuery(TableId tableId, List<String> snapsho
}
else {
String query = snapshotSelectColumns.stream()
.collect(Collectors.joining(", ", "SELECT ", " FROM " + tableId.toDoubleQuotedString()));
.collect(Collectors.joining(", ", "SELECT ", " FROM ONLY " + tableId.toDoubleQuotedString()));

return Optional.of(query);
}
Expand Down

0 comments on commit d60696b

Please sign in to comment.