Skip to content

Commit

Permalink
sql: remove sequence ownership dependency when dropping sequences
Browse files Browse the repository at this point in the history
Previously, when a sequence that was owned by a column was being
dropped, we would not remove the sequence ID from the column descriptor
of the column that owned it. As a result, there was a bug where if the
sequence was dropped manually before the table, it would be impossible
to drop the table.

This patch addresses this problem by removing the ownership dependency
on sequence drops.

Fixes #50649

Release note (bug fix): there was a bug previously where if a user
created a sequence owned by a table's column and dropped the sequence,
it would become impossible to drop the table after. This is now fixed.
See attached issue for repro steps.
  • Loading branch information
arulajmani committed Jun 25, 2020
1 parent ae0f360 commit 6d9f2ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/sql/drop_sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (p *planner) dropSequenceImpl(
jobDesc string,
behavior tree.DropBehavior,
) error {
removeSequenceOwnerIfExists(ctx, p, seqDesc.ID, seqDesc.GetSequenceOpts())
return p.initiateDropTable(ctx, seqDesc, queueJob, jobDesc, true /* drainName */)
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/sequences
Original file line number Diff line number Diff line change
Expand Up @@ -1081,3 +1081,17 @@ CREATE TABLE c(a INT DEFAULT(currval('currval_dep_test')))

statement error pq: cannot drop sequence currval_dep_test because other objects depend on it
DROP SEQUENCE currval_dep_test

subtest regression_50649

statement ok
CREATE TABLE t_50649(a INT PRIMARY KEY)

statement ok
CREATE SEQUENCE seq_50649 OWNED BY t_50649.a

statement ok
DROP SEQUENCE seq_50649

statement ok
DROP TABLE t_50649

0 comments on commit 6d9f2ee

Please sign in to comment.