Skip to content

Commit

Permalink
sql: add drop type to the prepared statement generator
Browse files Browse the repository at this point in the history
Release justification: fixes for high-priority or high-severity bugs in existing functionality

Previously, prepare statement doesnt have support for drop type
in optimizer, so it panic during execution as no flags are generated.

This patch fixes this by adding dropType to the optimizer.

Resolves cockroachdb#61226

Release note: none

Signed-off-by: Tharun <rajendrantharun@live.com>
  • Loading branch information
tharun208 committed Mar 3, 2021
1 parent 6de4313 commit 8a3cdce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/sql/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestStatementReuses(t *testing.T) {
`CREATE SEQUENCE s`,
`CREATE INDEX woo ON a(b)`,
`CREATE USER woo`,
`CREATE TYPE test as ENUM('a')`,
}

for _, s := range initStmts {
Expand All @@ -54,6 +55,7 @@ func TestStatementReuses(t *testing.T) {
`DROP SEQUENCE s`,
`DROP VIEW v`,
`DROP USER woo`,
`DROP TYPE test`,

// Ditto ALTER first, so that erroneous side effects bork what's
// below.
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/prepare
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,10 @@ CREATE TABLE greeting_table (x greeting NOT NULL, y INT, INDEX (x, y))
statement ok
PREPARE enum_query AS SELECT x, y FROM greeting_table WHERE y = 2

# Create prepared statement to drop type.
statement ok
PREPARE enum_drop AS DROP TYPE greeting

# Now alter the enum to have a new value.
statement ok
ALTER TYPE greeting ADD VALUE 'howdy'
Expand All @@ -1368,3 +1372,11 @@ query TI
EXECUTE enum_query
----
howdy 2

# drop table
statement ok
DROP TABLE greeting_table

# drop the type using prepared statement.
statement ok
EXECUTE enum_drop
4 changes: 2 additions & 2 deletions pkg/sql/plan_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (p *planner) prepareUsingOptimizer(ctx context.Context) (planFlags, error)
*tree.CreateSequence,
*tree.CreateStats,
*tree.Deallocate, *tree.Discard, *tree.DropDatabase, *tree.DropIndex,
*tree.DropTable, *tree.DropView, *tree.DropSequence,
*tree.Execute,
*tree.DropTable, *tree.DropView, *tree.DropSequence, *tree.DropType,
*tree.Execute, *tree.Explain,
*tree.Grant, *tree.GrantRole,
*tree.Prepare,
*tree.ReleaseSavepoint, *tree.RenameColumn, *tree.RenameDatabase,
Expand Down

0 comments on commit 8a3cdce

Please sign in to comment.