-
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: provide table comments for virtual tables #34764
sql: provide table comments for virtual tables #34764
Conversation
pkg/sql/crdb_internal.go
Outdated
e := vEntries[virtSchemaName] | ||
for _, tName := range e.orderedDefNames { | ||
table := e.defs[tName].desc | ||
if err := addRow( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make a single function that takes the desc as argument and does the common thing between this and below
pkg/sql/crdb_internal.go
Outdated
@@ -644,6 +673,7 @@ CREATE TABLE crdb_internal.session_trace ( | |||
message STRING NOT NULL, -- The logged message. | |||
age INTERVAL NOT NULL -- The age of this message relative to the beginning of the trace. | |||
)`, | |||
comment: "latest trace collected on this session (via SET TRACING={ON/OFF}).", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit/style: when we opt out of full sentences (no capital at start) we also opt out of the final period. (Same as cluster settings)
Conversely you could opt into the capitals.
pkg/sql/crdb_internal.go
Outdated
@@ -736,7 +768,8 @@ func (p *planner) makeSessionsRequest(ctx context.Context) serverpb.ListSessions | |||
// crdbInternalLocalQueriesTable exposes the list of running queries | |||
// on the current node. The results are dependent on the current user. | |||
var crdbInternalLocalQueriesTable = virtualSchemaTable{ | |||
schema: fmt.Sprintf(queriesSchemaPattern, "node_queries"), | |||
schema: fmt.Sprintf(queriesSchemaPattern, "node_queries"), | |||
comment: "the list of running queries on the current node. The results are dependent on the current user.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistent articles (either use "the" or not at start, but do the same consistently)
pkg/sql/crdb_internal.go
Outdated
@@ -960,7 +996,7 @@ var crdbInternalLocalMetricsTable = virtualSchemaTable{ | |||
name STRING NOT NULL, -- name of the metric | |||
value FLOAT NOT NULL -- value of the metric | |||
)`, | |||
|
|||
comment: "snapshot of the metrics on the current node.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure "snapshot" is necessary. I think it's implied for all the tables.
pkg/sql/crdb_internal.go
Outdated
@@ -1038,6 +1075,7 @@ CREATE TABLE crdb_internal.create_statements ( | |||
validate_statements STRING[] NOT NULL | |||
) | |||
`, | |||
comment: "exposes the CREATE TABLE/CREATE VIEW statements.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the CREATE statements". No need to be specific, also your current phrasing would already be inaccurate.
8cde54f
to
75ad40e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz)
pkg/sql/crdb_internal.go, line 209 at r1 (raw file):
Previously, knz (kena) wrote…
make a single function that takes the desc as argument and does the common thing between this and below
Done.
pkg/sql/crdb_internal.go, line 676 at r1 (raw file):
nit/style: when we opt out of full sentences (no capital at start) we also opt out of the final period. (Same as cluster settings)
I choose to opt out of the final period.
pkg/sql/crdb_internal.go, line 772 at r1 (raw file):
Previously, knz (kena) wrote…
inconsistent articles (either use "the" or not at start, but do the same consistently)
Done.
pkg/sql/crdb_internal.go, line 999 at r1 (raw file):
Previously, knz (kena) wrote…
not sure "snapshot" is necessary. I think it's implied for all the tables.
Done.
pkg/sql/crdb_internal.go, line 1078 at r1 (raw file):
"the CREATE statements". No need to be specific, also your current phrasing would already be inaccurate.
I deleted the unnecessary comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your changes. I have some more suggestions below.
Reviewed 2 of 8 files at r1, 6 of 6 files at r2.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @hueypark)
pkg/server/admin.go, line 1494 at r2 (raw file):
dbName := (*string)(row[2].(*tree.DString)) if sqlbase.IsVirtualTable(sqlbase.ID(tableID)) {
Thanks for noticing this. However I think this change belongs to a different PR. Can you extract it from this PR and file a different PR for this? Thank you
pkg/sql/crdb_internal.go, line 209 at r1 (raw file):
Previously, hueypark (Jaewan Park) wrote…
Done.
This will allocate an array, expand it and discard it for every row. Maybe it's a bit memory-heavy and inefficient? Consider this instead:
createTableRow := func(table *sqlbase.TableDescriptor, dbName string) error {
...
return addRow(...)
}
(i.e. use a closure)
then below
if err := createTableRow(table, dbName); err != nil {
return err
}
pkg/sql/crdb_internal.go, line 676 at r1 (raw file):
Previously, hueypark (Jaewan Park) wrote…
nit/style: when we opt out of full sentences (no capital at start) we also opt out of the final period. (Same as cluster settings)
I choose to opt out of the final period.
I still see the period here :)
this is a period: .
for example "latest trace collected on this session."
-> "latest trace collected on this session"
pkg/sql/show_tables.go, line 52 at r2 (raw file):
SELECT i.table_name, obj_description(t.table_id::REGCLASS) AS comment
This seems to be better because it's shorter, however it's objectively worse for performance: the query optimizer cannot "See through" obj_description
and see the join performed within, and cannot work to simplify the query. The result is that the comment table will be queried again for every table.
However I also understand that system.comment
does not contain the virtual table comments.
Maybe the right way to do this is to add a new virtual table in information_schema
(information_schema.comments
?) that contains all the data from system.comments
+ the data in the .comment
field for virtual tables.
This way you can preserve the join here, simply replacing system.comments
by information_schema.comments
.
75ad40e
to
7038a37
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your reviews. I changed the implementation based on your suggestion(add information_schema.comments
).
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @knz)
pkg/sql/crdb_internal.go, line 209 at r1 (raw file):
Previously, knz (kena) wrote…
This will allocate an array, expand it and discard it for every row. Maybe it's a bit memory-heavy and inefficient? Consider this instead:
createTableRow := func(table *sqlbase.TableDescriptor, dbName string) error { ... return addRow(...) }(i.e. use a closure)
then below
if err := createTableRow(table, dbName); err != nil { return err }
This function is now obsolete.
pkg/sql/crdb_internal.go, line 676 at r1 (raw file):
Previously, knz (kena) wrote…
I still see the period here :)
this is a period:
.
for example
"latest trace collected on this session."
->"latest trace collected on this session"
Done.
pkg/sql/show_tables.go, line 52 at r2 (raw file):
Previously, knz (kena) wrote…
This seems to be better because it's shorter, however it's objectively worse for performance: the query optimizer cannot "See through"
obj_description
and see the join performed within, and cannot work to simplify the query. The result is that the comment table will be queried again for every table.However I also understand that
system.comment
does not contain the virtual table comments.Maybe the right way to do this is to add a new virtual table in
information_schema
(information_schema.comments
?) that contains all the data fromsystem.comments
+ the data in the.comment
field for virtual tables.This way you can preserve the join here, simply replacing
system.comments
byinformation_schema.comments
.
Done.
And I've added an id column to the information_schema.tables
table to eliminate the unnecessary JOIN.
pkg/server/admin.go, line 1494 at r2 (raw file):
Previously, knz (kena) wrote…
Thanks for noticing this. However I think this change belongs to a different PR. Can you extract it from this PR and file a different PR for this? Thank you
Done.
But, This was necessary to pass the test If I do not use information_schema.comments
approach.
7038a37
to
6edb5d1
Compare
crdb_internal
dee5a08
to
3cf9062
Compare
3cf9062
to
0d7ee51
Compare
This patch adds a `comment` to `virtualSchemaTable` and exposes it through a new virtual table `crdb_internal.predefined_comments`. This is then used by `pg_catalog.pg_description` to expose comments on virtual tables alongside those of real tables. This way `obj_description()` works on virtual tables too. Finally it modifies `SHOW TABLES WITH COMMENT` to use `pg_description` and expose the table comments. Release note (sql change): CockroachDB now provides usable comments with optional documentation URLs for the virtual tables in `pg_catalog`, `information_schema` and `crdb_internal`. Use `SHOW TABLES [FROM ...] WITH COMMENT` to read. Note that `crdb_internal` tables remain an experimental feature subject to change without notice.
0d7ee51
to
336a9fa
Compare
Thank you for your changes. All it all it was a good improvement. I made a few last minute changes, including fixing Again thank you for your efforts! bors r+ |
34764: sql: provide table comments for virtual tables r=knz a=hueypark Fixes #32964 Fixes #35581 Release note (sql change): CockroachDB now provides usable comments with optional documentation URLs for the virtual tables in `pg_catalog`, `information_schema` and `crdb_internal`. Use `SHOW TABLES [FROM ...] WITH COMMENT` to read. Note that `crdb_internal` tables remain an experimental feature subject to change without notice. Co-authored-by: Jaewan Park <jaewan.huey.park@gmail.com>
Build succeeded |
Fixes #32964
Fixes #35581
Release note (sql change): CockroachDB now provides usable comments
with optional documentation URLs for the virtual tables in
pg_catalog
,information_schema
andcrdb_internal
. UseSHOW TABLES [FROM ...] WITH COMMENT
to read. Note thatcrdb_internal
tables remain an experimental feature subject to change without
notice.