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

optimize the list partition pruner for range query, #22144

Closed
crazycs520 opened this issue Jan 4, 2021 · 2 comments · Fixed by #22294
Closed

optimize the list partition pruner for range query, #22144

crazycs520 opened this issue Jan 4, 2021 · 2 comments · Fixed by #22294
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/performance

Comments

@crazycs520
Copy link
Contributor

crazycs520 commented Jan 4, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduction step (Required)

For the list partition table:

set @@session.tidb_enable_table_partition = nightly;
create table t (id int) partition by list  (id) (
	    partition p0 values in (1,2),
	    partition p1 values in (3,4),
	    partition p3 values in (5,null)
	);

Currently, range query can't prune partition:

test> desc select * from t where id < 3;
+------------------------+----------+-----------+-----------------------+--------------------------------+
| id                     | estRows  | task      | access object         | operator info                  |
+------------------------+----------+-----------+-----------------------+--------------------------------+
| PartitionUnion_9       | 9970.00  | root      |                       |                                |
| ├─TableReader_12       | 3323.33  | root      |                       | data:Selection_11              |
| │ └─Selection_11       | 3323.33  | cop[tikv] |                       | lt(test.t.id, 3)               |
| │   └─TableFullScan_10 | 10000.00 | cop[tikv] | table:t, partition:p0 | keep order:false, stats:pseudo |
| ├─TableReader_15       | 3323.33  | root      |                       | data:Selection_14              |
| │ └─Selection_14       | 3323.33  | cop[tikv] |                       | lt(test.t.id, 3)               |
| │   └─TableFullScan_13 | 10000.00 | cop[tikv] | table:t, partition:p1 | keep order:false, stats:pseudo |
| └─TableReader_18       | 3323.33  | root      |                       | data:Selection_17              |
|   └─Selection_17       | 3323.33  | cop[tikv] |                       | lt(test.t.id, 3)               |
|     └─TableFullScan_16 | 10000.00 | cop[tikv] | table:t, partition:p3 | keep order:false, stats:pseudo |
+------------------------+----------+-----------+-----------------------+--------------------------------+

But actually, we can use id < 3 to do partition prune, since only partition p0 contain the value that id<3. The expected result is:

test> desc select * from t where id < 3;
+------------------------+----------+-----------+-----------------------+--------------------------------+
| id                     | estRows  | task      | access object         | operator info                  |
+------------------------+----------+-----------+-----------------------+--------------------------------+
| PartitionUnion_9       | 9970.00  | root      |                       |                                |
| ├─TableReader_12       | 3323.33  | root      |                       | data:Selection_11              |
|   └─Selection_11       | 3323.33  | cop[tikv] |                       | lt(test.t.id, 3)               |
|     └─TableFullScan_10 | 10000.00 | cop[tikv] | table:t, partition:p0 | keep order:false, stats:pseudo |
+------------------------+----------+-----------+-----------------------+--------------------------------+

Idea

Use a BTree to store the all list partition values, for range query, traversal the range to find the partition in this range.

Samely, the list column partition can also use this optimization.

4. What is your TiDB version? (Required)

test> select tidb_version();
+-------------------------------------------------------------------+
| tidb_version()                                                    |
+-------------------------------------------------------------------+
| Release Version: v4.0.0-beta.2-1948-g9cb4fb38d                    |
| Edition: Community                                                |
| Git Commit Hash: 9cb4fb38d844204b7acba35f1784405c86476dbc         |
| Git Branch: master                                                |
| UTC Build Time: 2021-01-04 03:34:31                               |
| GoVersion: go1.15.6                                               |
| Race Enabled: false                                               |
| TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306 |
| Check Table Before Drop: false                                    |
+-------------------------------------------------------------------+
@crazycs520 crazycs520 added type/bug The issue is confirmed as a bug. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/performance and removed type/bug The issue is confirmed as a bug. labels Jan 4, 2021
@TszKitLo40
Copy link
Contributor

I want to try this issue.

@TszKitLo40
Copy link
Contributor

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/performance
Projects
None yet
2 participants