From 761ec85486b21dbd0c25c62b1525cb47d583fc49 Mon Sep 17 00:00:00 2001 From: Rafi Shamim Date: Sun, 3 Apr 2022 23:19:59 -0400 Subject: [PATCH] sql: fix `SHOW SCHEMAS FROM` to include user-defined schemas The search query had a broken join condition which would incorrectly filter out user-defined schemas, since using the unqualified pg_catalog would only look in the current database. Release note (bug fix): Fixed a bug where `SHOW SCHEMAS FROM ` would not include user-defined schemas. --- pkg/sql/delegate/show_schemas.go | 4 ++-- pkg/sql/logictest/testdata/logic_test/database | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/sql/delegate/show_schemas.go b/pkg/sql/delegate/show_schemas.go index 247b09da42e0..e26a66cd128f 100644 --- a/pkg/sql/delegate/show_schemas.go +++ b/pkg/sql/delegate/show_schemas.go @@ -30,8 +30,8 @@ func (d *delegator) delegateShowSchemas(n *tree.ShowSchemas) (tree.Statement, er getSchemasQuery := fmt.Sprintf(` SELECT nspname AS schema_name, rolname AS owner FROM %[1]s.information_schema.schemata i - INNER JOIN pg_catalog.pg_namespace n ON (n.nspname = i.schema_name) - LEFT JOIN pg_catalog.pg_roles r ON (n.nspowner = r.oid) + INNER JOIN %[1]s.pg_catalog.pg_namespace n ON (n.nspname = i.schema_name) + LEFT JOIN %[1]s.pg_catalog.pg_roles r ON (n.nspowner = r.oid) WHERE catalog_name = %[2]s ORDER BY schema_name`, name.String(), // note: (tree.Name).String() != string(name) diff --git a/pkg/sql/logictest/testdata/logic_test/database b/pkg/sql/logictest/testdata/logic_test/database index e90bc18c86cd..b1f314aada67 100644 --- a/pkg/sql/logictest/testdata/logic_test/database +++ b/pkg/sql/logictest/testdata/logic_test/database @@ -41,6 +41,10 @@ postgres root NULL {} NULL NULL system node NULL {} NULL NULL test root NULL {} NULL NULL +# Verify that SHOW SCHEMAS FROM a includes user-defined schemas. +statement ok +CREATE SCHEMA a.s + query TT colnames SHOW SCHEMAS FROM a ---- @@ -50,6 +54,7 @@ information_schema NULL pg_catalog NULL pg_extension NULL public admin +s root statement ok CREATE DATABASE b TEMPLATE=template0