Skip to content

Conversation

@danolivo
Copy link
Contributor

XXX:
There was a doubt about whether we need to support the LR of stored generated columns as the upstream does. This commit just skips them because of a) simplicity, and b) different types of generated columns have been introduced recently, and supporting LR, we would need to support two different implementations.

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

co-author: Claude.

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
@danolivo danolivo self-assigned this Dec 17, 2025
@danolivo danolivo added the enhancement New feature or request label Dec 17, 2025
@danolivo danolivo requested a review from mason-sharp December 17, 2025 10:47
Copy link
Member

@mason-sharp mason-sharp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving.

I tried pulling it down and reran the tests, changing STORED to VIRTUAL against Postgres 18, those passed as well.

@mason-sharp mason-sharp merged commit 3387e1a into main Dec 19, 2025
5 checks passed
@mason-sharp mason-sharp deleted the spoc-370 branch December 19, 2025 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants