cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
29.97k stars 3.79k forks source link

cdc query does not apply projection to previous value #131856

Open bobvawter opened 3 days ago

bobvawter commented 3 days ago

Consider the following table schema and sequence of changefeed messages:

create table t (pk int primary key using hash, a int not null, b int not null not visible);
upsert into t (pk,a,b) values (2,4,4);
upsert into t (pk,a,b) values (2,5,5);
delete from t where pk=2;
create changefeed with envelope='wrapped', diff as select *, crdb_internal_pk_shard_16 from t ;
{"key":"[6, 2]","table":"t","value":"{\"after\": {\"a\": 4, \"crdb_internal_pk_shard_16\": 6, \"pk\": 2}, \"before\": null}"}
{"key":"[6, 2]","table":"t","value":"{\"after\": {\"a\": 5, \"crdb_internal_pk_shard_16\": 6, \"pk\": 2}, \"before\": {\"a\": 4, \"b\": 4, \"pk\": 2}}"}
{"key":"[6, 2]","table":"t","value":"{\"after\": null, \"before\": {\"a\": 5, \"b\": 5, \"pk\": 2}}"}

The before block always emits the previous row value and not the requested projection. This is problematic in use cases where a projected value is required to successfully process a deletion.

Also note that the not-visible b column is present in the before value.

Jira issue: CRDB-42726

blathers-crl[bot] commented 3 days ago

Hi @bobvawter, please add branch-* labels to identify which branch(es) this C-bug affects.

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

blathers-crl[bot] commented 3 days ago

cc @cockroachdb/cdc