-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
statistics: do not load unnecessary index statistics #54060
statistics: do not load unnecessary index statistics #54060
Conversation
Signed-off-by: hi-rustin <[email protected]>
Signed-off-by: hi-rustin <[email protected]>
Signed-off-by: hi-rustin <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-7.5 #54060 +/- ##
================================================
Coverage ? 72.0278%
================================================
Files ? 1411
Lines ? 410758
Branches ? 0
================================================
Hits ? 295860
Misses ? 94993
Partials ? 19905
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Signed-off-by: hi-rustin <[email protected]>
Tested locally:
mysql> show stats_meta
-> ;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test | t | | 2024-06-18 12:07:12 | 0 | 0 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.01 sec)
mysql> select * from t where a = 1 and b = 1;
+------+------+
| a | b |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.01 sec)
Before:
mysql> show stats_meta
-> ;
+---------+------------+----------------+---------------------+--------------+-----------+
| Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count |
+---------+------------+----------------+---------------------+--------------+-----------+
| test | t | | 2024-06-18 12:07:12 | 0 | 0 |
+---------+------------+----------------+---------------------+--------------+-----------+
1 row in set (0.01 sec)
mysql> select * from t where a = 1 and b = 1;
+------+------+
| a | b |
+------+------+
| 1 | 1 |
+------+------+
1 row in set (0.01 sec)
|
Signed-off-by: hi-rustin <[email protected]>
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.
🔢 Self-check (PR reviewed by myself and ready for feedback.)
Signed-off-by: hi-rustin <[email protected]>
ad68231
to
08d7cd9
Compare
Signed-off-by: hi-rustin <[email protected]>
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.
🔢 Self-check (PR reviewed by myself and ready for feedback.)
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.
LGTM
You can add this desciption into |
Signed-off-by: hi-rustin <[email protected]>
require.Eventually(t, func() bool { | ||
rows := tk.MustQuery("show stats_meta").Rows() | ||
return len(rows) > 0 | ||
}, 2*time.Minute, 5*time.Millisecond) |
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.
We can use this to trigger it immediately.
require.Eventually(t, func() bool { | |
rows := tk.MustQuery("show stats_meta").Rows() | |
return len(rows) > 0 | |
}, 2*time.Minute, 5*time.Millisecond) | |
h := dom.StatsHandle() | |
require.NoError(t, h.DumpStatsDeltaToKV(true)) | |
require.NoError(t, h.Update(dom.InfoSchema())) |
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.
Nice! I forgot we can directly call an update here.
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.
Updated.
Signed-off-by: hi-rustin <[email protected]>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: elsa0520, time-and-fate The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
Signed-off-by: ti-chi-bot <[email protected]>
In response to a cherrypick label: new pull request created to branch |
What problem does this PR solve?
Issue Number: close #54022
Problem Summary:
See more at the issue.
A quick summary:
If you have
tidb_opt_objective='determine'
enabled, it will trigger some async stats load for some tables. If there tables histogram isn't in the system, it would cause some problems when we try to load it.What changed and how does it work?
Check that the index statistics are really needed before loading them.
If we don't check it here, it will cause some problems if the index statistics don't exist.
Note: We still don't know why the histogram record for the index is missing. There are some possible issues:
What happened in the test case:
statsHandle.Update(do.InfoSchema())
will load this table into the stats cache. You can test it by breakpoint here:mysql.stats_meta
.https://github.com/hi-rustin/tidb/blob/648fc6386aa9aabb365baf0912f1e18c4ab74d95/pkg/planner/core/logical_plan_builder.go#L4824
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.