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

*: implement analyze predicate columns #30816

Merged
merged 38 commits into from
Dec 30, 2021

Conversation

xuyifangreeneyes
Copy link
Contributor

@xuyifangreeneyes xuyifangreeneyes commented Dec 16, 2021

What problem does this PR solve?

Issue Number: close #31102

Problem Summary:

What is changed and how it works?

What is changed?

  1. Implement analyze table t predicate columns. When there is no predicate column for t, it gives a warning and falls back to analyze all columns.
  2. Introduce global variable tidb_enable_column_tracking, which controls whether to collect predicate columns from SQL and dump to disk. When set global tidb_enable_column_tracking = 0, all the predicate columns collected before are invalidated.

How it works?

  1. analyze table t predicate columns finds out predicate columns for t by reading from mysql.column_stats_usage. After figuring out which columns' stats need to be collected, the following thing is just the same as analyze table t columns c1, ..., cn.
  2. When set global tidb_enable_column_tracking = 0, we don't physically update mysql.column_stats_usage to invalidate predicate columns. Instead, we record the time of the setting operation in tidb_disable_column_tracking_time, which is a variable in the system variable mysql.tidb. When we want to get predicate columns, we read from mysql.column_stats_usage and filter out the columns whose last_used_at is null. Then we compare last_used_at with tidb_disable_column_tracking_time. last_used_at <= tidb_disable_column_tracking_time means that the predicate columns is invalidated. So we only regard the columns whose last_used_at > tidb_disable_column_tracking_time as predicate columns.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 16, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • qw4990
  • winoros

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 16, 2021
@xuyifangreeneyes
Copy link
Contributor Author

/cc @winoros @chrysan

@sre-bot
Copy link
Contributor

sre-bot commented Dec 20, 2021

@xuyifangreeneyes xuyifangreeneyes requested a review from a team as a code owner December 21, 2021 16:04
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 25, 2021
@xuyifangreeneyes xuyifangreeneyes changed the title *: periodically dump predicate columns to disk and implement analyze predicate columns *: implement analyze predicate columns Dec 29, 2021
@xuyifangreeneyes
Copy link
Contributor Author

/run-unit-test

@xuyifangreeneyes
Copy link
Contributor Author

/run-check_dev_2

@ti-chi-bot ti-chi-bot added status/LGT1 Indicates that a PR has LGTM 1. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Dec 29, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 29, 2021
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 30, 2021
@winoros
Copy link
Member

winoros commented Dec 30, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: f00e4a3

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 30, 2021
@xuyifangreeneyes
Copy link
Contributor Author

/run-unit-test

@xuyifangreeneyes
Copy link
Contributor Author

/run-check_dev_2

@ti-chi-bot ti-chi-bot merged commit 8085c99 into pingcap:master Dec 30, 2021
@xuyifangreeneyes xuyifangreeneyes deleted the impl-predicate-columns branch December 30, 2021 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement analyze predicate columns
5 participants