diff --git a/pkg/sql/drop_schema.go b/pkg/sql/drop_schema.go index 84a09dd52c27..78d8f939147d 100644 --- a/pkg/sql/drop_schema.go +++ b/pkg/sql/drop_schema.go @@ -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. diff --git a/pkg/sql/logictest/testdata/logic_test/schema b/pkg/sql/logictest/testdata/logic_test/schema index f7860d9f1af9..ab0ff47af43f 100644 --- a/pkg/sql/logictest/testdata/logic_test/schema +++ b/pkg/sql/logictest/testdata/logic_test/schema @@ -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;