fix: add primary keys to stats tables to prevent ctid-based update conflicts#1
Open
fuziontech wants to merge 1 commit into
Open
fix: add primary keys to stats tables to prevent ctid-based update conflicts#1fuziontech wants to merge 1 commit into
fuziontech wants to merge 1 commit into
Conversation
…rite safety When using PostgreSQL as the metadata catalog with multiple concurrent writers (e.g., Kafka Connect tasks), UPDATE/DELETE statements on tables without primary keys cause postgres_scanner to use ctid (physical row ID) for row identification. This leads to serialization failures because ctid changes when rows are updated due to PostgreSQL's MVCC. ## Primary Keys Added Tables that previously had no primary key now have one: | Table | Primary Key | |-------|-------------| | ducklake_table_stats | table_id | | ducklake_table_column_stats | (table_id, column_id) | | ducklake_file_column_stats | (data_file_id, column_id) | | ducklake_partition_info | partition_id | | ducklake_partition_column | (partition_id, partition_key_index) | | ducklake_file_partition_value | (data_file_id, partition_key_index) | | ducklake_files_scheduled_for_deletion | data_file_id | | ducklake_inlined_data_tables | (table_id, schema_version) | | ducklake_column_mapping | mapping_id | | ducklake_name_mapping | (mapping_id, column_id) | | ducklake_macro_impl | (macro_id, impl_id) | | ducklake_macro_parameters | (macro_id, impl_id, column_id) | ## Indexes Added For frequently queried columns (especially table_id lookups): - idx_data_file_table_snapshot: (table_id, begin_snapshot, end_snapshot) - idx_delete_file_table_snapshot: (table_id, begin_snapshot, end_snapshot) - idx_column_table: (table_id, end_snapshot) - idx_file_column_stats_table: (table_id, column_id) - idx_partition_info_table: (table_id) - idx_partition_column_table: (table_id) - idx_file_partition_value_table: (table_id) This eliminates "could not serialize access due to concurrent update" errors and improves query performance for table-scoped operations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
d1b7597 to
a61a2d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds PRIMARY KEY constraints and indexes to DuckLake metadata tables to prevent PostgreSQL serialization failures under concurrent writes and improve query performance.
Problem
When using PostgreSQL as the metadata catalog with multiple concurrent writers (e.g., 8 Kafka Connect tasks writing to the same table), we see frequent errors:
Root Cause
Many DuckLake metadata tables lack primary keys. When
postgres_scannerexecutes UPDATE/DELETE statements on tables without primary keys, it falls back to usingctid(PostgreSQL's physical row identifier) to locate rows. Thectidchanges whenever a row is updated (due to PostgreSQL's MVCC), causing concurrent updates to fail.Changes
Primary Keys Added
Indexes Added
For frequently queried columns (especially table_id lookups in data file queries):
Migration for Existing Catalogs
For existing PostgreSQL metadata catalogs, run these ALTER statements:
Test Plan
🤖 Generated with Claude Code