Closed matthewtodd closed 1 year ago
tl;dr check out "".crdb_internal.*
All of these "system catalogs" are namespaced for Postgres compatibility. Postgres doesn't know anything about stuff in other databases. Cockroach is in a somewhat different place because it tried to not be Postgres for a while and it originally just had a two level namespace. This turns out to have been a bad idea because compatibility is useful. Nevertheless, accessing global catalog information is also handy. Cockroach has a piece of somewhat bizarre syntax for this: the "" catalog. There are reasons why this thing might be regrettable, but it's what we've got.
Oh, upon reading again, I think it's a mistake that tables is not namespaced. We're an inconsistent mess.
At this point the reason to retain the behavior is backwards compat (😞). I'll do some spelunking to see if I can understand whether there was any rationale on this decision.
Thanks, @ajwerner, "".crdb_internal.*
will meet my current needs, and I suspect you're right about tables
.
We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB!
Describe the problem
The
crdb_internal.tables
virtual table lists all tables in all databases, butcrdb_internal.table_indexes
only lists indexes in the current database. I found this context-dependence surprising when writing queries to join these 2 tables for #61507.To Reproduce
See tables from all databases (here,
system
andmovr
) incrdb_internal.tables
:See only indexes from the current database (first
system
, thenmovr
) incrdb_internal.table_indexes
:Expected behavior
Given the stable contents of
crdb_internal.tables
, I expectedcrdb_internal.table_indexes
to also be stable, that is, to not change based on the current database, but to include all indexes for all tables. Perhaps there are reasons we'd like to retain the current behavior? But I wanted to at least mention it here.Jira issue: CRDB-7992