Skip to content

Commit

Permalink
Merge #61162 #61191
Browse files Browse the repository at this point in the history
61162: sql: add pg_class.relpartbound column r=RichardJCai a=rafiss

DBeaver relies on this column existing.

Release note (sql change): The pg_catalog.pg_class table now has a
relpartbound column. This is only for compatibility, and the column
value is always NULL.

Release justification: Low-risk, high-benefit change to existing
functionality.

61191: sql: fix SHOW TABLES FROM db stats display r=RichardJCai a=rafiss

fixes #58652

Release justification: low-risk bug fix to existing functionality.

Release note (bug fix): The `SHOW TABLES FROM database` command would
always show a NULL estimated_row_count if inspecting a database that was
not the current database. This is now fixed.

Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
craig[bot] and rafiss committed Feb 26, 2021
3 parents c943b6d + 32858d7 + fe801c7 commit 45deb66
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 187 deletions.
6 changes: 4 additions & 2 deletions pkg/sql/delegate/show_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ ORDER BY schema_name, table_name
var estimatedRowCountJoin string
if showEstimatedRowCountClusterSetting.Get(&d.evalCtx.Settings.SV) {
estimatedRowCount = "s.estimated_row_count AS estimated_row_count, "
estimatedRowCountJoin = `
LEFT JOIN crdb_internal.table_row_statistics AS s on (s.table_id = pc.oid::INT8)`
estimatedRowCountJoin = fmt.Sprintf(
`LEFT JOIN %[1]s.crdb_internal.table_row_statistics AS s on (s.table_id = pc.oid::INT8)`,
&name.CatalogName,
)
}
var descJoin string
var comment string
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/namespace
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public a table root 0 NULL
query TTTTIT
SHOW TABLES FROM public.public
----
public t table root NULL NULL
public t table root 0 NULL

# Of course one can also list the tables in "public" by making it the
# current database.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/rename_table
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ SHOW TABLES
query TTTTIT
SHOW TABLES FROM test2
----
public t table root NULL NULL
public t2 table root NULL NULL
public t table root 0 NULL
public t2 table root 0 NULL

user root

Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/rename_view
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ SHOW TABLES FROM test
query TTTTIT
SHOW TABLES FROM test2
----
public v view root NULL NULL
public v2 view root NULL NULL
public v view root 0 NULL
public v2 view root 0 NULL

user root

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/role
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ publicdb root NULL {} NULL
query TTTTIT
SHOW TABLES FROM publicdb
----
public publictable table root NULL NULL
public publictable table root 0 NULL

query TTTTIT
SHOW TABLES FROM privatedb
Expand Down
124 changes: 62 additions & 62 deletions pkg/sql/logictest/testdata/logic_test/show_source
Original file line number Diff line number Diff line change
Expand Up @@ -196,71 +196,71 @@ query TTTTIT colnames,rowsort
SELECT * FROM [SHOW TABLES FROM system]
----
schema_name table_name type owner estimated_row_count locality
public namespace table NULL NULL NULL
public migrations table NULL NULL NULL
public sqlliveness table NULL NULL NULL
public scheduled_jobs table NULL NULL NULL
public statement_diagnostics table NULL NULL NULL
public statement_diagnostics_requests table NULL NULL NULL
public statement_bundle_chunks table NULL NULL NULL
public role_options table NULL NULL NULL
public protected_ts_records table NULL NULL NULL
public protected_ts_meta table NULL NULL NULL
public namespace2 table NULL NULL NULL
public reports_meta table NULL NULL NULL
public replication_stats table NULL NULL NULL
public replication_critical_localities table NULL NULL NULL
public replication_constraint_stats table NULL NULL NULL
public comments table NULL NULL NULL
public role_members table NULL NULL NULL
public locations table NULL NULL NULL
public table_statistics table NULL NULL NULL
public web_sessions table NULL NULL NULL
public jobs table NULL NULL NULL
public ui table NULL NULL NULL
public rangelog table NULL NULL NULL
public eventlog table NULL NULL NULL
public lease table NULL NULL NULL
public tenants table NULL NULL NULL
public settings table NULL NULL NULL
public zones table NULL NULL NULL
public users table NULL NULL NULL
public descriptor table NULL NULL NULL

query TTTTTTT colnames,rowsort
public namespace table NULL 0 NULL
public migrations table NULL 0 NULL
public sqlliveness table NULL 0 NULL
public scheduled_jobs table NULL 0 NULL
public statement_diagnostics table NULL 0 NULL
public statement_diagnostics_requests table NULL 0 NULL
public statement_bundle_chunks table NULL 0 NULL
public role_options table NULL 0 NULL
public protected_ts_records table NULL 0 NULL
public protected_ts_meta table NULL 0 NULL
public namespace2 table NULL 0 NULL
public reports_meta table NULL 0 NULL
public replication_stats table NULL 0 NULL
public replication_critical_localities table NULL 0 NULL
public replication_constraint_stats table NULL 0 NULL
public comments table NULL 0 NULL
public role_members table NULL 0 NULL
public locations table NULL 0 NULL
public table_statistics table NULL 0 NULL
public web_sessions table NULL 0 NULL
public jobs table NULL 0 NULL
public ui table NULL 0 NULL
public rangelog table NULL 0 NULL
public eventlog table NULL 0 NULL
public lease table NULL 0 NULL
public tenants table NULL 0 NULL
public settings table NULL 0 NULL
public zones table NULL 0 NULL
public users table NULL 0 NULL
public descriptor table NULL 0 NULL

query TTTTITT colnames,rowsort
SELECT * FROM [SHOW TABLES FROM system WITH COMMENT]
----
schema_name table_name type owner estimated_row_count locality comment
public namespace table NULL NULL NULL ·
public migrations table NULL NULL NULL ·
public sqlliveness table NULL NULL NULL ·
public scheduled_jobs table NULL NULL NULL ·
public statement_diagnostics table NULL NULL NULL ·
public statement_diagnostics_requests table NULL NULL NULL ·
public statement_bundle_chunks table NULL NULL NULL ·
public role_options table NULL NULL NULL ·
public protected_ts_records table NULL NULL NULL ·
public protected_ts_meta table NULL NULL NULL ·
public namespace2 table NULL NULL NULL ·
public reports_meta table NULL NULL NULL ·
public replication_stats table NULL NULL NULL ·
public replication_critical_localities table NULL NULL NULL ·
public replication_constraint_stats table NULL NULL NULL ·
public comments table NULL NULL NULL ·
public role_members table NULL NULL NULL ·
public locations table NULL NULL NULL ·
public table_statistics table NULL NULL NULL ·
public web_sessions table NULL NULL NULL ·
public jobs table NULL NULL NULL ·
public ui table NULL NULL NULL ·
public rangelog table NULL NULL NULL ·
public eventlog table NULL NULL NULL ·
public lease table NULL NULL NULL ·
public tenants table NULL NULL NULL ·
public settings table NULL NULL NULL ·
public zones table NULL NULL NULL ·
public users table NULL NULL NULL ·
public descriptor table NULL NULL NULL ·
public namespace table NULL 0 NULL ·
public migrations table NULL 0 NULL ·
public sqlliveness table NULL 0 NULL ·
public scheduled_jobs table NULL 0 NULL ·
public statement_diagnostics table NULL 0 NULL ·
public statement_diagnostics_requests table NULL 0 NULL ·
public statement_bundle_chunks table NULL 0 NULL ·
public role_options table NULL 0 NULL ·
public protected_ts_records table NULL 0 NULL ·
public protected_ts_meta table NULL 0 NULL ·
public namespace2 table NULL 0 NULL ·
public reports_meta table NULL 0 NULL ·
public replication_stats table NULL 0 NULL ·
public replication_critical_localities table NULL 0 NULL ·
public replication_constraint_stats table NULL 0 NULL ·
public comments table NULL 0 NULL ·
public role_members table NULL 0 NULL ·
public locations table NULL 0 NULL ·
public table_statistics table NULL 0 NULL ·
public web_sessions table NULL 0 NULL ·
public jobs table NULL 0 NULL ·
public ui table NULL 0 NULL ·
public rangelog table NULL 0 NULL ·
public eventlog table NULL 0 NULL ·
public lease table NULL 0 NULL ·
public tenants table NULL 0 NULL ·
public settings table NULL 0 NULL ·
public zones table NULL 0 NULL ·
public users table NULL 0 NULL ·
public descriptor table NULL 0 NULL ·

query ITTT colnames
SELECT node_id, user_name, application_name, active_queries
Expand Down
21 changes: 19 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/show_tables
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
# LogicTest: local

statement ok
SET CLUSTER SETTING sql.show_tables.estimated_row_count.enabled = false
CREATE TABLE show_this_table()

query TTTTIT
SHOW TABLES
----
public show_this_table table root 0 NULL

statement ok
CREATE TABLE show_this_table()
CREATE DATABASE other;
SET DATABASE = 'other'

query TTTTIT
SHOW TABLES FROM test
----
public show_this_table table root 0 NULL

statement ok
SET DATABASE = 'test'

statement ok
SET CLUSTER SETTING sql.show_tables.estimated_row_count.enabled = false

query TTTTT
SHOW TABLES
Expand Down
60 changes: 30 additions & 30 deletions pkg/sql/logictest/testdata/logic_test/system
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ test root NULL {} NULL
query TTTTIT
SHOW TABLES FROM system
----
public comments table NULL NULL NULL
public descriptor table NULL NULL NULL
public eventlog table NULL NULL NULL
public jobs table NULL NULL NULL
public lease table NULL NULL NULL
public locations table NULL NULL NULL
public migrations table NULL NULL NULL
public namespace table NULL NULL NULL
public namespace2 table NULL NULL NULL
public protected_ts_meta table NULL NULL NULL
public protected_ts_records table NULL NULL NULL
public rangelog table NULL NULL NULL
public replication_constraint_stats table NULL NULL NULL
public replication_critical_localities table NULL NULL NULL
public replication_stats table NULL NULL NULL
public reports_meta table NULL NULL NULL
public role_members table NULL NULL NULL
public role_options table NULL NULL NULL
public scheduled_jobs table NULL NULL NULL
public settings table NULL NULL NULL
public sqlliveness table NULL NULL NULL
public statement_bundle_chunks table NULL NULL NULL
public statement_diagnostics table NULL NULL NULL
public statement_diagnostics_requests table NULL NULL NULL
public table_statistics table NULL NULL NULL
public tenants table NULL NULL NULL
public ui table NULL NULL NULL
public users table NULL NULL NULL
public web_sessions table NULL NULL NULL
public zones table NULL NULL NULL
public comments table NULL 0 NULL
public descriptor table NULL 0 NULL
public eventlog table NULL 0 NULL
public jobs table NULL 0 NULL
public lease table NULL 0 NULL
public locations table NULL 0 NULL
public migrations table NULL 0 NULL
public namespace table NULL 0 NULL
public namespace2 table NULL 0 NULL
public protected_ts_meta table NULL 0 NULL
public protected_ts_records table NULL 0 NULL
public rangelog table NULL 0 NULL
public replication_constraint_stats table NULL 0 NULL
public replication_critical_localities table NULL 0 NULL
public replication_stats table NULL 0 NULL
public reports_meta table NULL 0 NULL
public role_members table NULL 0 NULL
public role_options table NULL 0 NULL
public scheduled_jobs table NULL 0 NULL
public settings table NULL 0 NULL
public sqlliveness table NULL 0 NULL
public statement_bundle_chunks table NULL 0 NULL
public statement_diagnostics table NULL 0 NULL
public statement_diagnostics_requests table NULL 0 NULL
public table_statistics table NULL 0 NULL
public tenants table NULL 0 NULL
public ui table NULL 0 NULL
public users table NULL 0 NULL
public web_sessions table NULL 0 NULL
public zones table NULL 0 NULL

query I rowsort
SELECT id FROM system.descriptor
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/opt/exec/execbuilder/testdata/explain
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ vectorized: true
└── • render
└── • hash join (left outer)
│ equality: (column78) = (table_id)
│ equality: (column79) = (table_id)
├── • render
│ │
│ └── • hash join (left outer)
│ │ equality: (column60) = (table_id)
│ │ equality: (column61) = (table_id)
│ │
│ ├── • render
│ │ │
Expand Down Expand Up @@ -257,12 +257,12 @@ vectorized: true
└── • render
└── • hash join (left outer)
│ equality: (column83) = (table_id)
│ equality: (column84) = (table_id)
├── • render
│ │
│ └── • hash join (left outer)
│ │ equality: (column65) = (table_id)
│ │ equality: (column66) = (table_id)
│ │
│ ├── • render
│ │ │
Expand Down
Loading

0 comments on commit 45deb66

Please sign in to comment.