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

core: partition prune not work when partition key has a different type with constant #59123

Open
L-maple opened this issue Jan 22, 2025 · 1 comment · May be fixed by #59155
Open

core: partition prune not work when partition key has a different type with constant #59123

L-maple opened this issue Jan 22, 2025 · 1 comment · May be fixed by #59155
Assignees
Labels
component/tablepartition This issue is related to Table Partition of TiDB. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.

Comments

@L-maple
Copy link
Contributor

L-maple commented Jan 22, 2025

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

use test;
create table t(a int, b int, c int) partition by range(a) (
    partition p1 values less than (100),
    partition p2 values less than (200),
    partition pm values less than (MAXVALUE));
analyze table t;
explain select * from t where a between "123" and "199";

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

unnecessary partitions would be pruned, like MySQL result:

+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | t     | p2         | ALL  | NULL          | NULL | NULL    | NULL |    1 |   100.00 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+

3. What did you see instead (Required)

All partitions would be visited.
If the number of partitions are large(e.g., in our online DB, a table has more than 2000+ partititions),the select performance is really poor.

+-------------------------+----------+-----------+---------------+--------------------------------------------------------------------------------+
| id                      | estRows  | task      | access object | operator info                                                                  |
+-------------------------+----------+-----------+---------------+--------------------------------------------------------------------------------+
| TableReader_7           | 8000.00  | root      | partition:all | data:Selection_6                                                               |
| └─Selection_6           | 8000.00  | cop[tikv] |               | ge(cast(test.t.a, double BINARY), 123), le(cast(test.t.a, double BINARY), 199) |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                                                 |
+-------------------------+----------+-----------+---------------+--------------------------------------------------------------------------------+

4. What is your TiDB version? (Required)

+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-alpha-158-gba79f5078d-dirty
Edition: Community
Git Commit Hash: ba79f50
Git Branch: master
UTC Build Time: 2025-01-22 08:18:45
GoVersion: go1.23.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

@L-maple L-maple added the type/bug The issue is confirmed as a bug. label Jan 22, 2025
@L-maple L-maple changed the title core: partition prune not work when partition key has different type with predicates core: partition prune not work when partition key has a different type with constant Jan 23, 2025
@L-maple
Copy link
Contributor Author

L-maple commented Jan 23, 2025

/assign @L-maple

@Defined2014 Defined2014 added type/enhancement The issue or PR belongs to an enhancement. sig/sql-infra SIG: SQL Infra component/tablepartition This issue is related to Table Partition of TiDB. and removed type/bug The issue is confirmed as a bug. labels Jan 23, 2025
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. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
2 participants