Skip to content

Commit

Permalink
Merge #50665
Browse files Browse the repository at this point in the history
50665: sql: remove sequence ownership dependency when dropping sequences r=solongordon a=arulajmani

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.

Co-authored-by: arulajmani <[email protected]>
  • Loading branch information
craig[bot] and arulajmani committed Jun 25, 2020
2 parents dfbb581 + fe78658 commit f36e1c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/drop_sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (p *planner) dropSequenceImpl(
jobDesc string,
behavior tree.DropBehavior,
) error {
if err := removeSequenceOwnerIfExists(ctx, p, seqDesc.ID, seqDesc.GetSequenceOpts()); err != nil {
return err
}
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 f36e1c9

Please sign in to comment.