cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql/schemachanger: ALTER PRIMARY KEY .. USING HASH can make the hash column public too late

Open fqazi opened this issue 1 year ago • 2 comments

Previously, in the legacy schema changer, when executing ALTER TABLE PRIMARY KEY .. USING HASH... we have stages where a new primary index is public without all the columns inside it being public. This is unexpected, since the key columns / storing referenced in the primary key should be public at the same time as the index. This can cause issues for CDC: https://github.com/wenyihu6/cockroach/blob/2d4f2a14a05b8e23a134cad42b435886657f8172/pkg/ccl/changefeedccl/cdcevent/event.go#L312

We should ideally make sure the columns referenced by the primary key index are public at the same time. Or at the very least ensure this is guaranteed for key columns.

Jira issue: CRDB-41028

Epic CRDB-40419

fqazi avatar Aug 07 '24 13:08 fqazi

Digging into this more, I don't think there is any nice options here. I think it makes sense to have the column not be public but still be in the primary index, otherwise we can't support comma syntax properly (i.e. rollbacks would break). I'm going to make a patch for the CDC logic to tolerate this and add coverage.

fqazi avatar Aug 27 '24 19:08 fqazi

While working on this, can you also see if you can identify why https://github.com/cockroachdb/cockroach/issues/128420 is happening?

rafiss avatar Aug 28 '24 22:08 rafiss