From 6d9f2eed269a2028b9c3e9c78706363ca5314acc Mon Sep 17 00:00:00 2001 From: arulajmani Date: Thu, 25 Jun 2020 16:22:57 -0400 Subject: [PATCH] sql: remove sequence ownership dependency when dropping sequences 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. --- pkg/sql/drop_sequence.go | 1 + pkg/sql/logictest/testdata/logic_test/sequences | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/sql/drop_sequence.go b/pkg/sql/drop_sequence.go index d25c976310e9..57c4e0d91e88 100644 --- a/pkg/sql/drop_sequence.go +++ b/pkg/sql/drop_sequence.go @@ -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 */) } diff --git a/pkg/sql/logictest/testdata/logic_test/sequences b/pkg/sql/logictest/testdata/logic_test/sequences index f503ff0b1c29..cddadc782708 100644 --- a/pkg/sql/logictest/testdata/logic_test/sequences +++ b/pkg/sql/logictest/testdata/logic_test/sequences @@ -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