Skip to content

sql: use schema desc ID for OIDs in pg_catalog#88009

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20220915-schema-oids
Sep 16, 2022
Merged

sql: use schema desc ID for OIDs in pg_catalog#88009
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20220915-schema-oids

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Sep 15, 2022

Needed for #87606.

Prior to this patch, a synthetic OID was used for
"namespace" (schema) references in pg_catalog.

This was making it difficult/impossible to retrieve schema comments using a non-root SQL query, e.g. via

SELECT nspname AS schema,
       coalesce(pc.comment, sc.comment) as description
  FROM pg_catalog.pg_namespace t
LEFT OUTER JOIN system.comments sc
    ON t.oid = sc.object_id AND sc.type = 4
LEFT OUTER JOIN crdb_internal.predefined_comments pc
    ON t.oid = pc.object_id AND pc.type = 4

This patch fixes it.

Release note: None

@knz knz requested review from a team and ajwerner September 15, 2022 19:20
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Prior to this patch, a synthetic OID was used for
"namespace" (schema) references in `pg_catalog`.

This was making it difficult/impossible to retrieve
schema comments using a non-`root` SQL query, e.g. via

```sql
SELECT nspname AS schema,
       substr(coalesce(pc.comment, sc.comment), e'[^\n]{0,40}') as description
  FROM pg_catalog.pg_namespace t
LEFT OUTER JOIN system.comments sc
    ON t.oid = sc.object_id AND sc.type = 4
LEFT OUTER JOIN crdb_internal.predefined_comments pc
    ON t.oid = pc.object_id AND pc.type = 4
```

This patch fixes it.

Release note: None
@knz knz force-pushed the 20220915-schema-oids branch from 97f9cd9 to 0140d75 Compare September 15, 2022 21:10
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a great idea

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner)

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Sep 16, 2022

thank you!

bors r=rafiss

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 16, 2022

Build succeeded:

@craig craig bot merged commit 4b2ee12 into cockroachdb:master Sep 16, 2022
@knz knz deleted the 20220915-schema-oids branch September 16, 2022 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants