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

*: global stats consistency for dynamic prune #34695

Merged
merged 19 commits into from
May 19, 2022

Conversation

chrysan
Copy link
Contributor

@chrysan chrysan commented May 16, 2022

What problem does this PR solve?

Issue Number: close #34730

Problem Summary:
Refine the logic of analyze under dynamic prune mode, to avoid inconsistency between partition stats and global stats.
In static mode, we may have different column settings and different persisted analyze options for partitions. That's the root cause of inconsistency.

What is changed and how it works?

mysql> create table t (a int, b int, c int) partition by range (a) (partition p0 values less than (10), partition p1 values less than (20));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (1,1,1), (2,2,2), (11,11,11);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> set tidb_partition_prune_mode=dynamic;
Query OK, 0 rows affected (0.00 sec)

mysql> analyze table t partition p0 columns b with 1 topn, 1 buckets;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> show warnings;
+---------+------+--------------------------------------------------------------------------------+
| Level   | Code | Message                                                                        |
+---------+------+--------------------------------------------------------------------------------+
| Warning | 1105 | Ignore columns and options when analyze partition in dynamic mode              |
| Note    | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p0 |
+---------+------+--------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> analyze table t partition p1 columns c with 1 topn, 1 buckets;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

mysql> show warnings;
+---------+------+--------------------------------------------------------------------------------+
| Level   | Code | Message                                                                        |
+---------+------+--------------------------------------------------------------------------------+
| Warning | 1105 | Ignore columns and options when analyze partition in dynamic mode              |
| Note    | 1105 | Analyze use auto adjusted sample rate 1.000000 for table test.t's partition p1 |
+---------+------+--------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> select * from t where b>1 and c>1;

mysql> show stats_histograms where table_name like "t";
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
| Db_name | Table_name | Partition_name | Column_name | Is_index | Update_time         | Distinct_count | Null_count | Avg_col_size | Correlation |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
| test    | t          | global         | b           |        0 | 2022-05-17 15:00:56 |              3 |          0 |          0.5 |           0 |
| test    | t          | global         | c           |        0 | 2022-05-17 15:00:56 |              3 |          0 |          0.5 |           0 |
+---------+------------+----------------+-------------+----------+---------------------+----------------+------------+--------------+-------------+
2 rows in set (0.00 sec)

BTW:

mysql> set tidb_partition_prune_mode=dynamic;
Query OK, 0 rows affected, 1 warning (2.25 sec)

mysql> show warnings;
+---------+------+----------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                      |
+---------+------+----------------------------------------------------------------------------------------------+
| Warning | 1105 | Please analyze all partition tables again for consistency between partition and global stats |
+---------+------+----------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented May 16, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Yisaer
  • xuyifangreeneyes

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.

@chrysan chrysan requested a review from a team as a code owner May 16, 2022 08:37
@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue 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 May 16, 2022
@sre-bot
Copy link
Contributor

sre-bot commented May 17, 2022

@chrysan chrysan changed the title *: global stats ready for dynamic prune *: global stats consistency for dynamic prune May 17, 2022
Copy link
Contributor

@Yisaer Yisaer left a comment

Choose a reason for hiding this comment

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

I found that there exists lots of duplciated assertion code in unit test, can we extract it as common function?

executor/analyze_test.go Show resolved Hide resolved
executor/analyze_test.go Outdated Show resolved Hide resolved
executor/analyze_test.go Outdated Show resolved Hide resolved
executor/analyze_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@xuyifangreeneyes xuyifangreeneyes left a comment

Choose a reason for hiding this comment

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

rest LGTM

executor/analyze_test.go Show resolved Hide resolved
executor/analyze_test.go Outdated Show resolved Hide resolved
executor/analyze_test.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 18, 2022
@chrysan
Copy link
Contributor Author

chrysan commented May 18, 2022

I found that there exists lots of duplciated assertion code in unit test, can we extract it as common function?

Not too many in common, prefer to keep the flexibility.

@chrysan chrysan requested a review from Yisaer May 19, 2022 02:33
@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 May 19, 2022
@chrysan
Copy link
Contributor Author

chrysan commented May 19, 2022

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: bbc8b81

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 19, 2022
@ti-chi-bot ti-chi-bot merged commit 2cf1354 into pingcap:master May 19, 2022
@sre-bot
Copy link
Contributor

sre-bot commented May 19, 2022

TiDB MergeCI notify

🔴 Bad News! [1] CI still failing after this pr merged.
These failed integration tests don't seem to be introduced by the current PR.

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci/integration-cdc-test 🔴 failed 1, success 33, total 34 29 min Existing failure
idc-jenkins-ci-tidb/integration-common-test 🟢 all 11 tests passed 11 min Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 6 min 32 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 6 min 1 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 5 min 51 sec Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 12 tests passed 5 min 40 sec Existing passed
idc-jenkins-ci-tidb/integration-ddl-test 🟢 all 6 tests passed 5 min 40 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 5 min 30 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 3 min 34 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

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.

global stats of partition table may be incorrect under dynamic prune mode
6 participants