cockroachdb / cockroachdb/cockroach
sql: speed up `SHOW TABLES`
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
The latency of `SHOW TABLES` increases with the number of rows in `system.table_statistics`, which is scanned in order to populate the `estimated_row_count` column. In workloads that create many tables, `SHOW TABLES` latency can increase to tens of seconds even if those tables are dropped later because their stats can remain in `system.table_statistics` for a while before being GC'd.
The current workaround is to disable the `estimated_row_count` column of `SHOW TABLES` with the cluster setting:
```sql
SET CLUSTER SETTING sql.show_tables.estimated_row_count.enabled = false;
```
I think there are some other improvements we can make.
- [x] The query used to populate the `crdb_internal.table_row_statistics` virtual table scans the `system.table_statistics` table twice. We should be able to rewrite the query so it only scans it once.
- https://github.com/cockroachdb/cockroach/pull/143446
- [ ] The query collects the estimated row count for all tables, even ones that are not active. Adding a filter for active table IDs to the query may speed it up by filtering before sorting/aggregation or by allowing it to use a constrained scan.
Jira issue: CRDB-48835
Contributor guide
Assessment
This issue has not been assessed yet.