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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/sequences
Original file line number Diff line number Diff line change
Expand Up @@ -2536,3 +2536,25 @@ SELECT substring(sequence_schema FOR 7), sequence_name FROM [SHOW SEQUENCES] WHE
pg_temp temp_seq

subtest end


subtest incorrect_cleanup_of_owned_by

statement ok
CREATE TABLE t_seq_owner (id BIGSERIAL NOT NULL);

statement ok
CREATE SEQUENCE id_seq_owned OWNED BY t_seq_owner.id;

statement ok
ALTER TABLE t_seq_owner ALTER COLUMN id SET DEFAULT nextval('id_seq_owned');

statement ok
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.

----
0

subtest end
1 change: 0 additions & 1 deletion pkg/sql/schemachanger/scexec/scmutationexec/helpers.go
Original file line number Diff line number Diff line change
Expand 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.)

return nil
}

Expand Down
Loading