-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: implement new crdb_internal virtual tables to inspect descriptors #17422
Conversation
The views in pg_catalog and information_schema provide introspection over the logical schema (pure SQL view) however when testing/debugging it is also important to see the descriptor IDs and also other fields of descriptors. This patch provides help for debugging with the following new virtual tables: - `crdb_internal.table_columns`: detailed column IDs and properties - `crdb_internal.table_indexes`: detailed index IDs and index properties - `crdb_internal.index_columns`: what columns are indexed and how - `crdb_internal.backward_dependencies`: which other descriptors each descriptor depends on - `crdb_internal.forward_dependencies`: which other descriptors each descriptor is depended on by These virtual tables are intended to display the contents of descriptors without any data transformation, so as to reveal any error in the descriptors, if any. Debugging/fsck tools can later use these to check schema validity.
cc6b153
to
1c2919a
Compare
Review status: 0 of 7 files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. pkg/sql/crdb_internal.go, line 59 at r1 (raw file):
s/Indices/Indexes pkg/sql/crdb_internal.go, line 997 at r1 (raw file):
It's a pity we log an error here rather than return an error to the user pkg/sql/crdb_internal.go, line 1004 at r1 (raw file):
same Comments from Reviewable |
... because it was incomplete (missing FK relationships). The two new tables `crdb_internal.forward_dependencies` and `crdb_internal.backward_dependencies` can be used instead.
TFYR! Review status: 0 of 7 files reviewed at latest revision, 3 unresolved discussions. pkg/sql/crdb_internal.go, line 59 at r1 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/crdb_internal.go, line 997 at r1 (raw file): Previously, vivekmenezes wrote…
Added a comment to clarify. pkg/sql/crdb_internal.go, line 1004 at r1 (raw file): Previously, vivekmenezes wrote…
ditto Comments from Reviewable |
Nice! |
Is there also a virtual table exposing the descriptors themselves (as serialized protos)? Cause that's what got me all excited. Line 421 in e554249
(it'd need to support the historical read sql syntax, but hopefully that'd happen automatically) Review status: 0 of 7 files reviewed at latest revision, 3 unresolved discussions, all commit checks successful. Comments from Reviewable |
@andreimatei what are you talking about? We do not need a virtual table; |
Oh I didn't know about Also @vivekmenezes since this Line 421 in e554249
|
The logic currently implemented by the new tables would be very cumbersome to express in pure SQL. Adding a bunch of built-in functions to decode the descriptors and provide this logic would work too, however I figured that a virtual tables provides a more natural approach to inspect this type of data. |
Note for example that these vtables can be subject of joins, whereas built-in functions that extract arrays from descriptors would not be easily usable in joins. |
The views in pg_catalog and information_schema provide introspection
over the logical schema (pure SQL view) however when testing/debugging
it is also important to see the descriptor IDs and also other fields
of descriptors.
This patch provides help for debugging with the following new virtual
tables:
crdb_internal.table_columns
: detailed column IDs and propertiescrdb_internal.table_indexes
: detailed index IDs and index propertiescrdb_internal.index_columns
: what columns are indexed and howcrdb_internal.backward_dependencies
: which other descriptors each descriptor depends oncrdb_internal.forward_dependencies
: which other descriptors each descriptor is depended on byThese virtual tables are intended to display the contents of
descriptors without any data transformation, so as to reveal any error
in the descriptors, if any.
Debugging/fsck tools can later use these to check schema validity.
Needed to test #17310.
cc @cockroachdb/sql