Fix replication errors with tables containing generated columns - #592
Conversation
PostgreSQL generated columns (GENERATED ALWAYS AS ... STORED) were causing errors during Spock replication. The issue occurred because generated columns were being treated as regular columns during: - Initial table synchronization (COPY operations) - Logical replication protocol messages - Default value filling for missing attributes - Conflict resolution and tuple processing Generated columns should not be replicated since they are computed automatically on the target database based on their definition. Solution: Add checks for attgenerated flag alongside existing attisdropped checks throughout the codebase to skip generated columns in: - spock_sync.c: COPY attribute list construction - spock_apply_heap.c: Default value filling - spock_proto_native.c: Native protocol tuple serialization - spock_proto_json.c: JSON protocol handling - spock_conflict.c: Conflict tuple formatting - spock_jsonb_utils.c: JSONB conversion utilities - spock_functions.c: Replication set table info - spock_repset.c: Attribute name lookup Test Coverage: Added regression test in sync_table.sql that verifies: - Table with STORED generated column can be added to replication set - Initial table synchronization works correctly via sub_resync_table() - Generated column values are correctly computed on subscriber - Both initial sync and ongoing replication handle generated columns
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | -2 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
PostgreSQL generated columns (GENERATED ALWAYS AS ... STORED) were causing errors during Spock replication. The issue occurred because generated columns were being treated as regular columns during:
Generated columns should not be replicated since they are computed automatically on the target database based on their definition.
Solution:
Add checks for attgenerated flag alongside existing attisdropped checks throughout the codebase to skip generated columns in:
Test Coverage:
Added regression test in sync_table.sql that verifies: