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

List partition can't prune access partition with greater or less condition #56673

Closed
Defined2014 opened this issue Oct 16, 2024 · 1 comment · Fixed by #56725
Closed

List partition can't prune access partition with greater or less condition #56673

Defined2014 opened this issue Oct 16, 2024 · 1 comment · Fixed by #56725
Assignees
Labels
component/tablepartition This issue is related to Table Partition of TiDB. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@Defined2014
Copy link
Contributor

Defined2014 commented Oct 16, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t` (
  `a` int NOT NULL,
  `b` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
/*!50100 PARTITION BY LIST (`a`)
(PARTITION p0 VALUES IN (null, 1,2,3) ENGINE = InnoDB,
 PARTITION p2 VALUES IN (-1,-2,-3) ENGINE = InnoDB,
 PARTITION p1 VALUES IN (100,101,102) ENGINE = InnoDB) */;
explain select * from t where a > 0;  -- access p0,p1
explain select * from t where a < 0;  -- access p2

2. What did you expect to see? (Required)

prune success

mysql> explain select * from t where a > 0;
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type  | possible_keys | key     | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | t     | p0,p1      | range | PRIMARY       | PRIMARY | 4       | NULL |    1 |   100.00 | Using where |
+----+-------------+-------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.00 sec)

3. What did you see instead (Required)

access all partitions

mysql> explain select * from t where a > 0;
+------------------------+---------+-----------+---------------+------------------------------------------------+
| id                     | estRows | task      | access object | operator info                                  |
+------------------------+---------+-----------+---------------+------------------------------------------------+
| TableReader_6          | 3333.33 | root      | partition:all | data:TableRangeScan_5                          |
| └─TableRangeScan_5     | 3333.33 | cop[tikv] | table:t       | range:(0,+inf], keep order:false, stats:pseudo |
+------------------------+---------+-----------+---------------+------------------------------------------------+
2 rows in set (0.01 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                 |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.4.0-alpha-419-g3df0f2e927-dirty
Edition: Community
Git Commit Hash: 3df0f2e927a4d1d5b9431ab4dc0f5a2a71f04786
Git Branch: master
UTC Build Time: 2024-10-16 02:36:14
GoVersion: go1.23.1
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
@Defined2014 Defined2014 added type/bug The issue is confirmed as a bug. sig/sql-infra SIG: SQL Infra severity/moderate component/tablepartition This issue is related to Table Partition of TiDB. labels Oct 16, 2024
@Defined2014
Copy link
Contributor Author

Defined2014 commented Oct 18, 2024

Use table schema below could prune unrelated partitions, but the performance is worse.

CREATE TABLE `t` (
  `a` int(11) NOT NULL,
  `b` varchar(255) COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
PARTITION BY LIST COLUMNS(`a`)
(PARTITION `p0` VALUES IN (1,2,3),
 PARTITION `p2` VALUES IN (-1,-2,-3),
 PARTITION `p1` VALUES IN (100,101,102));

mysql> explain select * from t where a > 0;
+------------------------+---------+-----------+-----------------+------------------------------------------------+
| id                     | estRows | task      | access object   | operator info                                  |
+------------------------+---------+-----------+-----------------+------------------------------------------------+
| TableReader_6          | 3333.33 | root      | partition:p0,p1 | data:TableRangeScan_5                          |
| └─TableRangeScan_5     | 3333.33 | cop[tikv] | table:t         | range:(0,+inf], keep order:false, stats:pseudo |
+------------------------+---------+-----------+-----------------+------------------------------------------------+
2 rows in set (0.01 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tablepartition This issue is related to Table Partition of TiDB. severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant