Open ghost opened 4 years ago
@imtbkcat @tiancaiamao PTAL
Integrity check: component severity RCA symptom trigger_condition affect_version fix_version fields are empty @imtbkcat Please comment /info to get template
This looks mostly fixed, with the exception of TiDB needing to access {p2018, p2019}
. MySQL can prune this to just p2018
- is there an off-by-one error in pruning?
mysql> EXPLAIN SELECT COUNT(*) FROM t1 WHERE d >= '2018-01-01' AND d < '2019-01-01';
+------------------------------------+----------+-----------+---------------------------+--------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+------------------------------------+----------+-----------+---------------------------+--------------------------------------------------------------------------------------+
| HashAgg_15 | 1.00 | root | | funcs:count(Column#4)->Column#3 |
| └─PartitionUnion_16 | 2.00 | root | | |
| ├─StreamAgg_31 | 1.00 | root | | funcs:count(Column#6)->Column#4 |
| │ └─TableReader_32 | 1.00 | root | | data:StreamAgg_20 |
| │ └─StreamAgg_20 | 1.00 | cop[tikv] | | funcs:count(1)->Column#6 |
| │ └─Selection_30 | 250.00 | cop[tikv] | | ge(test.t1.d, 2018-01-01 00:00:00.000000), lt(test.t1.d, 2019-01-01 00:00:00.000000) |
| │ └─TableFullScan_29 | 10000.00 | cop[tikv] | table:t1, partition:p2018 | keep order:false, stats:pseudo |
| └─StreamAgg_50 | 1.00 | root | | funcs:count(Column#8)->Column#4 |
| └─TableReader_51 | 1.00 | root | | data:StreamAgg_39 |
| └─StreamAgg_39 | 1.00 | cop[tikv] | | funcs:count(1)->Column#8 |
| └─Selection_49 | 250.00 | cop[tikv] | | ge(test.t1.d, 2018-01-01 00:00:00.000000), lt(test.t1.d, 2019-01-01 00:00:00.000000) |
| └─TableFullScan_48 | 10000.00 | cop[tikv] | table:t1, partition:p2019 | keep order:false, stats:pseudo |
+------------------------------------+----------+-----------+---------------------------+--------------------------------------------------------------------------------------+
12 rows in set (0.00 sec)
mysql> EXPLAIN SELECT COUNT(*) FROM t1 WHERE d >= '2018-01-01' AND d < '2018-12-31';
+----------------------------+---------+-----------+---------------------------+--------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------+---------+-----------+---------------------------+--------------------------------------------------------------------------------------+
| StreamAgg_12 | 1.00 | root | | funcs:count(1)->Column#3 |
| └─TableReader_19 | 0.07 | root | | data:Selection_18 |
| └─Selection_18 | 0.07 | cop[tikv] | | ge(test.t1.d, 2018-01-01 00:00:00.000000), lt(test.t1.d, 2018-12-31 00:00:00.000000) |
| └─TableFullScan_17 | 3.00 | cop[tikv] | table:t1, partition:p2018 | keep order:false, stats:pseudo |
+----------------------------+---------+-----------+---------------------------+--------------------------------------------------------------------------------------+
4 rows in set (0.01 sec)
mysql> EXPLAIN SELECT COUNT(*) FROM t1 WHERE d >= '2018-01-01' AND d <= '2018-12-31';
+----------------------------+---------+-----------+---------------------------+--------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------+---------+-----------+---------------------------+--------------------------------------------------------------------------------------+
| StreamAgg_12 | 1.00 | root | | funcs:count(1)->Column#3 |
| └─TableReader_19 | 0.07 | root | | data:Selection_18 |
| └─Selection_18 | 0.07 | cop[tikv] | | ge(test.t1.d, 2018-01-01 00:00:00.000000), le(test.t1.d, 2018-12-31 00:00:00.000000) |
| └─TableFullScan_17 | 3.00 | cop[tikv] | table:t1, partition:p2018 | keep order:false, stats:pseudo |
+----------------------------+---------+-----------+---------------------------+--------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
/info
Note: Make Sure that 'component', and 'severity' labels are added Example for how to fill out the template: https://github.com/pingcap/tidb/issues/20100
Same with dynamic prune mode:
tidb> set @@session.tidb_partition_prune_mode = dynamic;
Query OK, 0 rows affected (0,00 sec)
tidb> EXPLAIN SELECT COUNT(*) FROM t1 WHERE d >= '2018-01-01' AND d < '2019-01-01';
+------------------------------+----------+-----------+-----------------------+--------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+------------------------------+----------+-----------+-----------------------+--------------------------------------------------------------------------------------+
| StreamAgg_20 | 1.00 | root | | funcs:count(Column#5)->Column#3 |
| └─TableReader_21 | 1.00 | root | partition:p2018,p2019 | data:StreamAgg_9 |
| └─StreamAgg_9 | 1.00 | cop[tikv] | | funcs:count(1)->Column#5 |
| └─Selection_19 | 250.00 | cop[tikv] | | ge(test.t1.d, 2018-01-01 00:00:00.000000), lt(test.t1.d, 2019-01-01 00:00:00.000000) |
| └─TableFullScan_18 | 10000.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo |
+------------------------------+----------+-----------+-----------------------+--------------------------------------------------------------------------------------+
5 rows in set (0,00 sec)
The difference between MySQL and TiDB is that MySQL will check the 'transitions' for YEAR() function, so MySQL will prune correctly for < '2019-01-01'
while TiDB will not. Notice that this is only for the "first transition value" and TiDB will prune correctly for < '2019-01-02
(which includes the p2019
partition).
/component tablepartition
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
In MySQL (see "partitions" column):
3. What did you see instead (Required)
In TiDB (see "access object"):
4. What is your TiDB version? (Required)