-
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: init LastAnalyzeVersion with snapshot timestamp #54465
statistics: init LastAnalyzeVersion with snapshot timestamp #54465
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #54465 +/- ##
=================================================
- Coverage 72.8339% 55.5985% -17.2355%
=================================================
Files 1551 1672 +121
Lines 436700 609230 +172530
=================================================
+ Hits 318066 338723 +20657
- Misses 99093 247472 +148379
- Partials 19541 23035 +3494
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Tested locally:
mysql> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.2.0-alpha-469-gc983546c52
Edition: Community
Git Commit Hash: c983546c525f7278946ceb67540d8d74448d3ef0
Git Branch: HEAD
UTC Build Time: 2024-07-01 06:02:24
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set global tidb_analyze_column_options='PREDICATE';
Query OK, 0 rows affected (0.01 sec)
mysql> select @@tidb_analyze_column_options;
+-------------------------------+
| @@tidb_analyze_column_options |
+-------------------------------+
| PREDICATE |
+-------------------------------+
1 row in set (0.00 sec)
CREATE TABLE test.random_data (
id INT,
value VARCHAR(100)
);
INSERT INTO test.random_data (value)
SELECT
CONCAT('RandomValue', FLOOR(RAND() * 10000))
FROM
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) t1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) t2,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) t3;
mysql> select * from mysql.stats_meta;
+------------------+--------+------------+-----+------------------+
|version |table_id|modify_count|count|snapshot |
+------------------+--------+------------+-----+------------------+
|450928411885961235|104 |0 |1000 |450928411885961225|
+------------------+--------+------------+-----+------------------+
After:
mysql> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.2.0-alpha-527-gba34df6c91
Edition: Community
Git Commit Hash: ba34df6c91c46d82ce3e07b79823ffc0d0480513
Git Branch: master
UTC Build Time: 2024-07-05 03:51:07
GoVersion: go1.22.2
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set global tidb_analyze_column_options='PREDICATE';
Query OK, 0 rows affected (0.01 sec)
mysql> select @@tidb_analyze_column_options;
+-------------------------------+
| @@tidb_analyze_column_options |
+-------------------------------+
| PREDICATE |
+-------------------------------+
1 row in set (0.00 sec)
CREATE TABLE test.random_data (
id INT,
value VARCHAR(100)
);
INSERT INTO test.random_data (value)
SELECT
CONCAT('RandomValue', FLOOR(RAND() * 10000))
FROM
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) t1,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) t2,
(SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) t3;
+------------------+--------+------------+-----+------------------+
|version |table_id|modify_count|count|snapshot |
+------------------+--------+------------+-----+------------------+
|450928506810662939|104 |0 |1000 |450928506810662922|
+------------------+--------+------------+-----+------------------+
|
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.)
I also tested the show statements: mysql> analyze table t;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> show stats_meta;
+---------+------------+----------------+---------------------+--------------+-----------+---------------------+
| Db_name | Table_name | Partition_name | Update_time | Modify_count | Row_count | Last_analyze_time |
+---------+------------+----------------+---------------------+--------------+-----------+---------------------+
| test | t | | 2024-07-12 16:59:33 | 0 | 3 | 2024-07-12 16:59:32 |
+---------+------------+----------------+---------------------+--------------+-----------+---------------------+
1 row in set (0.00 sec)
mysql> SHOW STATS_HEALTHY;
+---------+------------+----------------+---------+
| Db_name | Table_name | Partition_name | Healthy |
+---------+------------+----------------+---------+
| test | t | | 100 |
+---------+------------+----------------+---------+
1 row in set (0.00 sec)
mysql> SHOW STATS_HISTOGRAMS;
Empty set (0.01 sec) |
36c4200
to
daf23ff
Compare
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.)
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 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 |
/hold |
[LGTM Timeline notifier]Timeline:
|
/unhold |
/retest |
What problem does this PR solve?
Issue Number: ref #53567
Problem Summary:
It only occurs in the following situations:
So in this case, the auto-analyze will try to analyze it again and again.
If you find an actual case and attempt to compare the snapshot from stats_meta with the version from the histogram, you will always find that this equation is true.
450928595500531720 - 450928595513638913 = -13,107,193
So we can safely use the snapshot to initialize the LastAnalyzeVersion.
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.