Skip to content

release-26.2: sql: clean up column deps during rollback of CREATE TABLE in ADD state#166223

Merged
rafiss merged 1 commit intocockroachdb:release-26.2from
shghasemi:blathers/backport-release-26.2-166015
Mar 19, 2026
Merged

release-26.2: sql: clean up column deps during rollback of CREATE TABLE in ADD state#166223
rafiss merged 1 commit intocockroachdb:release-26.2from
shghasemi:blathers/backport-release-26.2-166015

Conversation

@shghasemi
Copy link
Copy Markdown
Contributor

@shghasemi shghasemi commented Mar 19, 2026

Backport 1/1 commits from #166015 on behalf of @shghasemi.


Previously, when a CREATE TABLE with user-defined type columns or sequence defaults was rolled back (e.g., due to a schema change job failure), the table's ID was left in the type descriptor's ReferencingDescriptorIDs and the sequence's DependedOnBy. After GC removed the table descriptor, these descriptors would have orphaned back-references to a non-existent descriptor, causing them to appear in crdb_internal.invalid_objects.

The fix adds a dropColumnDeps method that iterates over the table's columns, finds all referenced user-defined type descriptors and sequences, and removes the table's ID from their back-references. This is called during rollbackSchemaChange alongside the existing dropFKDeps.

Fixes: #165836

Release note (bug fix): Fixed a bug where rolling back a CREATE TABLE that referenced user-defined types or sequences would leave orphaned back-references on the type and sequence descriptors, causing them to appear in crdb_internal.invalid_objects after the table was GC'd.


Release justification: fix for bug that can cause descriptor corruption

Previously, when a CREATE TABLE with user-defined type columns or
sequence defaults was rolled back (e.g., due to a schema change job
failure), the table's ID was left in the type descriptor's
ReferencingDescriptorIDs and the sequence's DependedOnBy. After GC
removed the table descriptor, these descriptors would have orphaned
back-references to a non-existent descriptor, causing them to appear
in crdb_internal.invalid_objects.

The fix adds a dropColumnDeps method that iterates over the table's
columns, finds all referenced user-defined type descriptors and
sequences, and removes the table's ID from their back-references.
This is called during rollbackSchemaChange alongside the existing
dropFKDeps.

Fixes: cockroachdb#165836

Release note (bug fix): Fixed a bug where rolling back a CREATE TABLE
that referenced user-defined types or sequences would leave orphaned
back-references on the type and sequence descriptors, causing them to
appear in crdb_internal.invalid_objects after the table was GC'd.
@shghasemi shghasemi requested a review from a team as a code owner March 19, 2026 21:35
@blathers-crl blathers-crl bot added blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. labels Mar 19, 2026
@blathers-crl blathers-crl bot requested a review from rafiss March 19, 2026 21:35
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Mar 19, 2026

⚠️ End-of-Life Version Warning

This backport targets 26.2, which is an End-of-Life (EOL) version.

Please verify that backporting to this EOL version is intentional and appropriate. EOL versions no longer receive maintenance updates according to our support policy.


Thanks for opening a backport.

Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate.

@blathers-crl blathers-crl bot added backport Label PR's that are backports to older release branches T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) labels Mar 19, 2026
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@rafiss rafiss merged commit fd3a317 into cockroachdb:release-26.2 Mar 19, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Label PR's that are backports to older release branches blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) target-release-26.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants