cockroachdb / cockroachdb/cockroach
cdc query does not apply projection to previous value
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
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
Epic CRDB-41786
Contributor guide
Assessment
This issue has not been assessed yet.