Skip to content

sql/schemachanger: fix incorrect clean up of sequnece ownership #151947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fqazi
Copy link
Collaborator

@fqazi fqazi commented Aug 15, 2025

Previously, when a default expression was cleaned up the sequence ownerships would be incorrectly cleaned up. This meant when we added support for setting default expressions in the declarative schema changer, any updates could wipe out sequence ownership information. To address this, this patch removes the incorrect clean up logic.

Fixes: #151925

Release note (bug fix): Updating column default expressions would incorrectly remove sequence ownerships for the affected column.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@fqazi fqazi added backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.2.x Flags PRs that need to be backported to 25.2 backport-25.3.x backport-25.3.1-rc Wednesday, 08/27: release-25.3.1-rc will be frozen labels Aug 15, 2025
Previously, when a default expression was cleaned up the sequence
ownerships would be incorrectly cleaned up. This meant when we added
support for setting default expressions in the declarative schema
changer, any updates could wipe out sequence ownership information. To
address this, this patch removes the incorrect clean up logic.

Fixes: cockroachdb#151925

Release note (bug fix): Updating column default expressions would
incorrectly remove sequence ownerships for the affected column.
@fqazi fqazi force-pushed the fixBadDefaultExpressionCleanup branch from 5e94eea to b978807 Compare August 18, 2025 13:09
@fqazi fqazi marked this pull request as ready for review August 18, 2025 13:09
@fqazi fqazi requested a review from a team as a code owner August 18, 2025 13:09
drop table t_seq_owner;

query I
SELECT count(*) FROM [SHOW TABLES] WHERE table_name='id_seq_owned'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we look at the pg_sequences table instead? and let's also make sure t_seq_owner_id_seq got cleaned up.

@@ -280,7 +280,6 @@ func updateColumnExprSequenceUsage(d *descpb.ColumnDescriptor) error {
ids.ForEach(all.Add)
}
d.UsesSequenceIds = all.Ordered()
d.OwnsSequenceIds = all.Ordered()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing i'm wondering is if we need to special case IDENTITY columns. aren't those implemented with a default expression, and the column should own the backing sequence? or is that handled separately? (since tests passed i assume it's fine, but i'm just curious.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-24.1.x Flags PRs that need to be backported to 24.1. backport-24.3.x Flags PRs that need to be backported to 24.3 backport-25.2.x Flags PRs that need to be backported to 25.2 backport-25.3.x backport-25.3.1-rc Wednesday, 08/27: release-25.3.1-rc will be frozen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql/schemachanger: sequence is not dropped with table
3 participants