catalog: scope pg_description classoid lookups to pg_catalog schema#37071
Open
aljoscha wants to merge 2 commits into
Open
catalog: scope pg_description classoid lookups to pg_catalog schema#37071aljoscha wants to merge 2 commits into
aljoscha wants to merge 2 commits into
Conversation
`pg_catalog.pg_description` derives each comment's `classoid` from `mz_internal.pg_description_all_databases`, which looked up the `pg_class`/`pg_type`/`pg_namespace` system catalog oids with unscoped scalar subqueries (`WHERE relname = 'pg_class'`, etc.). A user object named after one of those catalogs, in any schema, made the scalar subquery match multiple rows, so `pg_description` errored with "more than one record produced in subquery" for everyone. Scope the lookups to the `pg_catalog` schema via a small CTE. The `pg_catalog` schema is ambient and reserved (users cannot create a schema with the `pg_` prefix), so the lookup resolves to exactly one row. This matches PostgreSQL, where `pg_description` is a real catalog table and is unaffected by user objects sharing those names. Fixes SQL-278.
…ption The pg_description_all_databases optimized plan changed because the classoid lookups are now scoped to the pg_catalog schema. Regenerated the golden EXPLAIN output. Fixes SQL-278.
aljoscha
commented
Jun 16, 2026
| cte l1 = | ||
| →Differential Join %1[#0] » %0:l0[#1{relname}] | ||
| →Arranged l0 | ||
| →Differential Join %1[#0] » %0:pg_namespace_all_databases[#1{nspname}] |
Contributor
Author
There was a problem hiding this comment.
@ggevay I think you added these recently? I see that we're doing things differently now, which makes sense because we have an additional lookup. But couldn't say whether that's fine or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Fixes SQL-278.
Creating any user object named
pg_class,pg_type, orpg_namespacein any schema broke
pg_catalog.pg_descriptionfor everyone:pg_descriptionderives each comment'sclassoidfrommz_internal.pg_description_all_databases, which looked up the systemcatalog oids with unscoped scalar subqueries (
WHERE relname = 'pg_class', etc.). A user object sharing one of those names made thescalar subquery match multiple rows, so the whole view errored.
Description
Scope the
pg_class/pg_type/pg_namespacelookups to thepg_catalogschema via a smallpg_catalog_classCTE. Thepg_catalogschema is ambient and reserved (users cannot create a schema with the
pg_prefix), so each lookup resolves to exactly one row. Only theclassoid derivation needed scoping; no other builtin view has the same
unscoped-lookup pattern.
This matches PostgreSQL, where
pg_descriptionis a real catalog tableand is unaffected by user objects that happen to share those names.
Verification
Verified against PostgreSQL 16: creating
public.pg_classdoes notaffect
pg_description; a commented user table's comment is stillreturned.
Added a regression test to
test/sqllogictest/comment.sltthat createsuser tables named
pg_class,pg_type, andpg_namespaceand assertspg_descriptionstill returns a user object's comment instead oferroring.