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

Some predicates should not be removed after partition pruning #33966

Closed
Reminiscent opened this issue Apr 14, 2022 · 0 comments · Fixed by #35298
Closed

Some predicates should not be removed after partition pruning #33966

Reminiscent opened this issue Apr 14, 2022 · 0 comments · Fixed by #35298
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@Reminiscent
Copy link
Contributor

Enhancement

Related to #22079
We will prune some partitions based on the predicate conditions and the predicate conditions will be removed when we use the static mode.
But some predicate conditions are required to generate a range for index access and cannot be eliminated.
For example:

drop table if exists t;
create table t(a int, b int, c int, unique index idx(a, b, c)) PARTITION BY RANGE ( `a` ) (
  PARTITION `PART_202101` VALUES LESS THAN (202102),
  PARTITION `PART_202102` VALUES LESS THAN (202103),
  PARTITION `PART_202103` VALUES LESS THAN (202104)
);
explain select count(*) from t where a = 202103 and b = 1 and c = 1;

The plan is

mysql> drop table if exists t;
Query OK, 0 rows affected (0.02 sec)

mysql> create table t(a int, b int, c int, unique index idx(a, b, c)) PARTITION BY RANGE ( `a` ) (
    ->   PARTITION `PART_202101` VALUES LESS THAN (202102),
    ->   PARTITION `PART_202102` VALUES LESS THAN (202103),
    ->   PARTITION `PART_202103` VALUES LESS THAN (202104)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> 
mysql> 
mysql> explain select count(*) from t where a = 202103 and b = 1 and c = 1;
+----------------------------+----------+-----------+----------------------------------------------------+----------------------------------+
| id                         | estRows  | task      | access object                                      | operator info                    |
+----------------------------+----------+-----------+----------------------------------------------------+----------------------------------+
| StreamAgg_12               | 1.00     | root      |                                                    | funcs:count(1)->Column#5         |
| └─IndexReader_24           | 0.01     | root      |                                                    | index:Selection_23               |
|   └─Selection_23           | 0.01     | cop[tikv] |                                                    | eq(test.t.b, 1), eq(test.t.c, 1) |
|     └─IndexFullScan_22     | 10000.00 | cop[tikv] | table:t, partition:PART_202103, index:idx(a, b, c) | keep order:false, stats:pseudo   |
+----------------------------+----------+-----------+----------------------------------------------------+----------------------------------+
4 rows in set (0.01 sec)

But the expected plan is

mysql> explain select count(*) from t where a = 202103 and b = 1 and c = 1;
+-----------------------------+---------+-----------+-----------------------------+---------------------------------------------------------------+
| id                          | estRows | task      | access object               | operator info                                                 |
+-----------------------------+---------+-----------+-----------------------------+---------------------------------------------------------------+
| StreamAgg_16                | 1.00    | root      |                             | funcs:count(Column#7)->Column#5                               |
| └─IndexReader_17            | 1.00    | root      | partition:PART_202103       | index:StreamAgg_9                                             |
|   └─StreamAgg_9             | 1.00    | cop[tikv] |                             | funcs:count(1)->Column#7                                      |
|     └─IndexRangeScan_11     | 1.00    | cop[tikv] | table:t, index:idx(a, b, c) | range:[202103 1 1,202103 1 1], keep order:false, stats:pseudo |
+-----------------------------+---------+-----------+-----------------------------+---------------------------------------------------------------+
4 rows in set (0.01 sec)

Because the predicate a = 202103 has been removed, it can not use to build the index range.

@Reminiscent Reminiscent added type/enhancement The issue or PR belongs to an enhancement. component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner labels Apr 14, 2022
@Reminiscent Reminiscent added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 labels Apr 15, 2022
ti-chi-bot pushed a commit that referenced this issue Apr 15, 2022
@mjonss mjonss self-assigned this Jun 10, 2022
ti-chi-bot pushed a commit that referenced this issue Jun 14, 2022
ti-chi-bot pushed a commit that referenced this issue Aug 22, 2022
@chrysan chrysan added affects-5.4 This bug affects 5.4.x versions. and removed affects-5.4 This bug affects 5.4.x versions. labels Sep 22, 2022
ti-chi-bot pushed a commit that referenced this issue Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants