Skip to content

Commit 5e94eea

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 cd43ab3 commit 5e94eea

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pkg/sql/logictest/testdata/logic_test/sequences

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,3 +2536,25 @@ SELECT substring(sequence_schema FOR 7), sequence_name FROM [SHOW SEQUENCES] WHE
25362536
pg_temp temp_seq
25372537

25382538
subtest end
2539+
2540+
2541+
subtest incorrect_cleanup_of_owned_by
2542+
2543+
statement ok
2544+
CREATE TABLE t_seq_owner (id BIGSERIAL NOT NULL);
2545+
2546+
statement ok
2547+
CREATE SEQUENCE id_seq_owned OWNED BY t_seq_owner.id;
2548+
2549+
statement ok
2550+
ALTER TABLE t_seq_owner ALTER COLUMN id SET DEFAULT nextval('id_seq_owned');
2551+
2552+
statement ok
2553+
drop table t_seq_owner;
2554+
2555+
query I
2556+
SELECT COUNT(*) FROM [SHOW TABLES] WHERE table_name='id_seq_owned'
2557+
----
2558+
0
2559+
2560+
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)