Skip to content

Commit a25bc70

Browse files
committed
sql/schemachanger: fix incorrect clean up of sequnece ownership
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.
1 parent 5361c4c commit a25bc70

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pkg/sql/logictest/testdata/logic_test/sequences

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,3 +2526,39 @@ SELECT substring(sequence_schema FOR 7), sequence_name FROM [SHOW SEQUENCES] WHE
25262526
pg_temp temp_seq
25272527

25282528
subtest end
2529+
2530+
2531+
subtest incorrect_cleanup_of_owned_by
2532+
2533+
statement ok
2534+
CREATE TABLE t_seq_owner (id BIGSERIAL NOT NULL);
2535+
2536+
statement ok
2537+
CREATE SEQUENCE id_seq_owned OWNED BY t_seq_owner.id;
2538+
2539+
statement ok
2540+
ALTER TABLE t_seq_owner ALTER COLUMN id SET DEFAULT nextval('id_seq_owned');
2541+
2542+
# Confirm the sequence still exists.
2543+
query I
2544+
SELECT count(*) FROM pg_sequences WHERE sequencename='id_seq_owned';
2545+
----
2546+
1
2547+
2548+
2549+
statement ok
2550+
drop table t_seq_owner;
2551+
2552+
# Confirm the sequence is dropped.
2553+
query I
2554+
SELECT count(*) FROM pg_sequences WHERE sequencename='id_seq_owned';
2555+
----
2556+
0
2557+
2558+
# Confirm the table is dropped.
2559+
query I
2560+
SELECT count(*) FROM pg_tables WHERE tablename='t_seq_owner';
2561+
----
2562+
0
2563+
2564+
subtest end

pkg/sql/schemachanger/scexec/scmutationexec/helpers.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ func updateColumnExprSequenceUsage(d *descpb.ColumnDescriptor) error {
280280
ids.ForEach(all.Add)
281281
}
282282
d.UsesSequenceIds = all.Ordered()
283-
d.OwnsSequenceIds = all.Ordered()
284283
return nil
285284
}
286285

0 commit comments

Comments
 (0)