Skip to content
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: improve the SHOW TABLES query to avoid reading stats when unused #59838

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ajwerner
Copy link
Contributor

@ajwerner ajwerner commented Feb 5, 2021

There is a distinct relationship between tables and row statistics which
was previously not stated explicitly in the query and thus, the optimizer
was unable to eliminate the join against the statistics table when the
estimated_row_count column was not used.

Touches #58189.

Release note (performance improvement): Queries which use SHOW TABLES but
do not utilize the estimated_row_count column no longer need to look up
the table statistics.

@ajwerner ajwerner requested a review from rafiss February 5, 2021 06:50
@ajwerner ajwerner requested a review from a team as a code owner February 5, 2021 06:50
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rafiss)

LEFT JOIN crdb_internal.table_row_statistics AS s ON (s.table_id = pc.oid::INT8)
LEFT JOIN
(
SELECT DISTINCT ON (table_id) table_id, estimated_row_count FROM crdb_internal.table_row_statistics
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, do we achieve the same thing by adding a crdb_internal.table_row_statistics(table_id) virtual index? i forget if virtual indexes are required to be unique

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they are unique indexes.

@otan
Copy link
Contributor

otan commented Feb 5, 2021

ah i misread the intention of this. do you mind backporting it too? thanks!

There is a distinct relationship between tables and row statistics which
was previously not stated explicitly in the query and thus, the optimizer
was unable to eliminate the join against the statistics table when the
`estimated_row_count` column was not used.

Release note (performance improvement): Queries which use `SHOW TABLES` but
do not utilize the `estimated_row_count` column no longer need to look up
the table statistics.
@ajwerner ajwerner force-pushed the ajwerner/better-show-tables-query branch from ce0f4c3 to 9773f4b Compare February 10, 2021 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants