tidb
tidb copied to clipboard
EXTRACT(YEAR FROM col) partitioning expression does not prune partitions
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
create table t (a datetime, b varchar(255)) partition by range (extract(year from a)) (partition p2020 values less than (2021), partition p2021 values less than (2022), partition pMax values less than (maxvalue));
insert into t values ('2020-12-31 23:59:59','2020-12-31 23:59:59'),('2021-01-01', '2021-01-01');
explain select * from t where a = '2020-12-31 23:59:59';
2. What did you expect to see? (Required)
That only partition p2020 would be used.
tidb> explain select * from t where a = '2020-12-31 23:59:59';
+-------------------------+----------+-----------+-----------------+------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+-----------------+------------------------------------------+
| TableReader_7 | 10.00 | root | partition:p2020 | data:Selection_6 |
| └─Selection_6 | 10.00 | cop[tikv] | | eq(test.t.a, 2020-12-31 23:59:59.000000) |
| └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+-----------------+------------------------------------------+
3. What did you see instead (Required)
All partitions where used.
tidb> explain select * from t where a = '2020-12-31 23:59:59';
+-------------------------+----------+-----------+---------------+------------------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+------------------------------------------+
| TableReader_7 | 10.00 | root | partition:all | data:Selection_6 |
| └─Selection_6 | 10.00 | cop[tikv] | | eq(test.t.a, 2020-12-31 23:59:59.000000) |
| └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+------------------------------------------+
4. What is your TiDB version? (Required)
tidb_version(): Release Version: v8.1.0
Edition: Community
Git Commit Hash: 945d07c5d5c7a1ae212f6013adfb187f2de24b23
Git Branch: HEAD
UTC Build Time: 2024-05-21 03:52:40
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv