Skip to content

Commit 8757f96

Browse files
authored
Merge pull request #152314 from fqazi/blathers/backport-release-25.2-151947
release-25.2: sql/schemachanger: fix incorrect clean up of sequence ownership
2 parents 75207f1 + a25bc70 commit 8757f96

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)