Open mjonss opened 3 years ago
I consider this only to be a minor bug, since MySQL 8.0.24 seems to prune this. But normally ranges should be large, so I think the benefit is more for non common use cases.
/type enhancement
/remove-type bug
/component tablepartition
> set @@tidb_partition_prune_mode = 'dynamic';
latest execution result of tidb.
> tidb> EXPLAIN SELECT * FROM t WHERE a != 1;
+-------------------------+---------+-----------+---------------+------------------+
| id | estRows | task | access object | operator info |
+-------------------------+---------+-----------+---------------+------------------+
| TableReader_7 | 1.00 | root | partition:all | data:Selection_6 |
| └─Selection_6 | 1.00 | cop[tikv] | | ne(test.t.a, 1) |
| └─TableFullScan_5 | 2.00 | cop[tikv] | table:t | keep order:false |
+-------------------------+---------+-----------+---------------+------------------+
I think the result is correct in the case above, but NOT IN and != is not handled in partition pruning that is exist.
CREATE TABLE t (a int, b varchar(255)) PARTITION BY list (a) (PARTITION p0 VALUES IN (1), PARTITION p1 VALUES IN (2));
Query OK, 0 rows affected (0.01 sec)
INSERT INTO t VALUES (2, "2"), (1,"1");
tidb> EXPLAIN SELECT * FROM t WHERE a != 1;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7 | 6656.67 | root | partition:all | data:Selection_6 |
| └─Selection_6 | 6656.67 | cop[tikv] | | ne(test.t.a, 1) |
| └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
tidb> EXPLAIN SELECT * FROM t WHERE a = 1;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id | estRows | task | access object | operator info |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7 | 10.00 | root | partition:p0 | data:Selection_6 |
| └─Selection_6 | 10.00 | cop[tikv] | | eq(test.t.a, 1) |
| └─TableFullScan_5 | 10000.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.01 sec)
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiDB version? (Required)
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | tidb_version() | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Release Version: v4.0.0-beta.2-2748-g8b0305aa2 Edition: Community Git Commit Hash: 8b0305aa2af38f201c893fe9ce8c9af4201ebbc8 Git Branch: master UTC Build Time: 2021-04-27 15:34:22 GoVersion: go1.16.3 Race Enabled: false TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306 Check Table Before Drop: false | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)