Skip to content

Commit

Permalink
Merge pull request #63397 from rafiss/backport20.2-63119
Browse files Browse the repository at this point in the history
release-20.2: sql: fix drop schema bug which corrupts schemas using the name of the db
  • Loading branch information
rafiss authored Apr 9, 2021
2 parents ae0d209 + 998f4db commit 31d3f45
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/drop_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func (p *planner) dropSchemaImpl(
if parentDB.Schemas == nil {
parentDB.Schemas = make(map[string]descpb.DatabaseDescriptor_SchemaInfo)
}
parentDB.Schemas[parentDB.Name] = descpb.DatabaseDescriptor_SchemaInfo{
ID: parentDB.ID,
parentDB.Schemas[sc.GetName()] = descpb.DatabaseDescriptor_SchemaInfo{
ID: sc.GetID(),
Dropped: true,
}
// Mark the descriptor as dropped.
Expand Down
33 changes: 33 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/schema
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,36 @@ query TT
SELECT schema_name, table_name FROM [SHOW TABLES FROM for_show.sc1]
----
sc1 t1

# Regression test for #62920. The bug that motivated this test would populate
# the schema entry in the database with the database's name rather than the
# schemas.
subtest schema_and_database_with_same_name

statement ok
CREATE DATABASE samename

statement ok
USE samename

statement ok
CREATE SCHEMA foo;
CREATE SCHEMA bar

statement ok
DROP SCHEMA foo

statement ok
CREATE SCHEMA samename

statement ok
DROP SCHEMA bar

statement ok
CREATE TABLE samename.samename.t (i INT PRIMARY KEY)

statement ok
SHOW TABLES

statement ok
DROP DATABASE samename CASCADE;

0 comments on commit 31d3f45

Please sign in to comment.