Skip to content

Partition pruning does not work with union. #13491

@SunRunAway

Description

@SunRunAway

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
CREATE TABLE partition_table (x int) PARTITION BY RANGE (x) ( 
PARTITION p1 VALUES LESS THAN (100), 
PARTITION p2 VALUES LESS THAN (200) 
);

It works without union

mysql> desc select * from partition_table where x > 100 ;
+---------------------+----------+-----------+----------------------------------------------------------------------------------------+
| id                  | count    | task      | operator info                                                                          |
+---------------------+----------+-----------+----------------------------------------------------------------------------------------+
| TableReader_8       | 3333.33  | root      | data:Selection_7                                                                       |
| └─Selection_7       | 3333.33  | cop[tikv] | gt(Column#1, 100)                                                                      |
|   └─TableScan_6     | 10000.00 | cop[tikv] | table:partition_table, partition:p2, range:[-inf,+inf], keep order:false, stats:pseudo |
+---------------------+----------+-----------+----------------------------------------------------------------------------------------+
3 rows in set (0.01 sec)
  1. What did you expect to see?

  2. What did you see instead?

But it does not work with one part of union.

mysql> desc select * from partition_table where x > 100 union select * from partition_table where x > 100;
+--------------------------------+----------+-----------+----------------------------------------------------------------------------------------+
| id                             | count    | task      | operator info                                                                          |
+--------------------------------+----------+-----------+----------------------------------------------------------------------------------------+
| HashAgg_17                     | 8000.00  | root      | group by:Column#7, funcs:firstrow(Column#7)                                            |
| └─Union_18                     | 10000.00 | root      |                                                                                        |
|   ├─Union_20                   | 6666.67  | root      |                                                                                        |
|   │ ├─TableReader_23           | 3333.33  | root      | data:Selection_22                                                                      |
|   │ │ └─Selection_22           | 3333.33  | cop[tikv] | gt(Column#4, 100)                                                                      |
|   │ │   └─TableScan_21         | 10000.00 | cop[tikv] | table:partition_table, partition:p1, range:[-inf,+inf], keep order:false, stats:pseudo |
|   │ └─TableReader_26           | 3333.33  | root      | data:Selection_25                                                                      |
|   │   └─Selection_25           | 3333.33  | cop[tikv] | gt(Column#4, 100)                                                                      |
|   │     └─TableScan_24         | 10000.00 | cop[tikv] | table:partition_table, partition:p2, range:[-inf,+inf], keep order:false, stats:pseudo |
|   └─TableReader_30             | 3333.33  | root      | data:Selection_29                                                                      |
|     └─Selection_29             | 3333.33  | cop[tikv] | gt(Column#1, 100)                                                                      |
|       └─TableScan_28           | 10000.00 | cop[tikv] | table:partition_table, partition:p2, range:[-inf,+inf], keep order:false, stats:pseudo |
+--------------------------------+----------+-----------+----------------------------------------------------------------------------------------+
12 rows in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

4a5bc92

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/feature-requestCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions