Skip to content

feat: add REPLICA IDENTITY NOTHING / USING INDEX support#91

Open
osmanok wants to merge 4 commits intoTrendyol:mainfrom
osmanok:feature/replica-identity-options
Open

feat: add REPLICA IDENTITY NOTHING / USING INDEX support#91
osmanok wants to merge 4 commits intoTrendyol:mainfrom
osmanok:feature/replica-identity-options

Conversation

@osmanok
Copy link
Contributor

@osmanok osmanok commented Feb 18, 2026

Summary

This MR adds full support for PostgreSQL replica identity modes NOTHING and USING INDEX, in addition to existing DEFAULT and FULL.

The change includes config support, validation, SQL execution changes, reconciliation/diff improvements, docs, and tests.

Background

Before this MR, table-level replica identity configuration supported only DEFAULT and FULL.
Issue #49 asks for support for the remaining PostgreSQL modes:

  • NOTHING
  • USING INDEX

These modes are important for workloads that want to reduce old-row payload size and use index-based key tuples for update/delete replication messages.

What Changed

1) Config model and validation

  • Added ReplicaIdentityIndex to publication.Table.
  • Extended supported identity options with NOTHING and USING INDEX.
  • Added validation rules:
    • ReplicaIdentityIndex is required when identity is USING INDEX.
    • ReplicaIdentityIndex must be empty for all other identity modes.

2) Replica identity execution and reconciliation

  • Added mapping support for PostgreSQL relreplident codes: d, f, n, i.
  • Updated AlterTableReplicaIdentity(...) to:
    • quote identifiers
    • emit REPLICA IDENTITY USING INDEX <index> for USING INDEX
  • Updated GetReplicaIdentities(...) to fetch both:
    • replica identity mode (relreplident)
    • replica identity index (pg_index.indisreplident join)
  • Updated table diff logic to include ReplicaIdentityIndex.

3) Operational safety/logging

  • Added a warning path when table identity is NOTHING while publication operations include UPDATE or DELETE.
  • Added Operations.Contains(...) helper used by the warning check.

4) Documentation updates

  • Expanded README config docs for:
    • supported replica identity values: DEFAULT, FULL, NOTHING, USING INDEX
    • new publication.tables[i].replicaIdentityIndex field
  • Added explanation of tuple behavior/trade-off:
    • FULL -> old tuple data (O)
    • USING INDEX -> key tuple data (K)

Behavior Matrix

Mode Old-row data on UPDATE/DELETE Notes
DEFAULT Primary key old values Existing behavior
FULL Full old row (O) Existing behavior
NOTHING No old tuple Usually suitable for insert-only patterns
USING INDEX Index key tuple (K) Lower payload, requires configured replica identity index

Test Coverage

Unit tests

  • pq/publication/table_test.go
    • validates ReplicaIdentityIndex rules
    • verifies diff behavior when index changes
  • pq/publication/replica_identity_test.go
    • verifies relreplident mapping (d/f/n/i)
    • verifies unknown-code fallback behavior
    • verifies helper behavior for table naming and literal quoting

Integration tests

Updated integration_test/system_identity_full_test.go with:

  • TestReplicaIdentityNothing
  • TestReplicaIdentityUsingIndex
  • TestReplicaIdentityUsingIndexUpdateUsesKeyTuple
  • TestReplicaIdentityUsingIndexMissingIndexReturnsError

Backward Compatibility

  • No behavior change for existing DEFAULT and FULL configurations.
  • New functionality is opt-in.
  • Misconfigurations for USING INDEX now fail early with explicit errors.

Risk Assessment

  • USING INDEX relies on valid PostgreSQL index constraints; invalid/missing index cases are covered with integration tests.
  • NOTHING with UPDATE/DELETE is allowed by design but now emits warning logs to make the trade-off explicit.
  • Identifier quoting and safer literal construction reduce malformed SQL/query risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant