Handle identity column change
What does this MR do?
This MR handles the case properly when the identity column (one of the primary key changes). The logical replication protocol will send the old identity column values in the OldTuple variable. This allows us to properly replicate some record changes.
Example:
Consider the issue_assignees table which has composite primary key:
Table "public.issue_assignees"
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
--------------+--------+-----------+----------+---------+---------+-------------+--------------+-------------
user_id | bigint | | not null | | plain | | |
issue_id | bigint | | not null | | plain | | |
namespace_id | bigint | | | | plain | | |
Indexes:
"issue_assignees_pkey" PRIMARY KEY, btree (issue_id, user_id)
It's a valid use case to update the user_id value:
UPDATE issue_assignees SET user_id = 2 WHERE user_id = 1
In Siphon, we would receive the updated tuple with user_id=2. This would create a problem in downstream data stores (like clickhouse) because we don't have a way to delete/change the old record. We simply don't have a reference to it.
With this change, when an identity column is updated, we send two events:
-
DELETEevent with the old identity column values. -
INSERTevent with the new tuple.
Additionally this issue unblocks the event partitioning issue, primary key changes are no longer an issue: #114 (comment 2445347610)