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

merge sort for partition table #22408

Closed
eurekaka opened this issue Jan 15, 2021 · 3 comments
Closed

merge sort for partition table #22408

eurekaka opened this issue Jan 15, 2021 · 3 comments
Labels
component/executor component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner

Comments

@eurekaka
Copy link
Contributor

eurekaka commented Jan 15, 2021

Feature Request

Is your feature request related to a problem? Please describe:

MySQL [test]> create table t(a int, b int) partition by range (a) (
    -> partition p0 values less than (5),
    -> partition p1 values less than (10),
    -> partition p2 values less than maxvalue
    -> );
Query OK, 0 rows affected (0.01 sec)

MySQL [test]> explain select * from t order by _tidb_rowid;
+--------------------------------+----------+-----------+-----------------------+--------------------------------+
| id                             | estRows  | task      | access object         | operator info                  |
+--------------------------------+----------+-----------+-----------------------+--------------------------------+
| Projection_10                  | 30000.00 | root      |                       | test.t.a, test.t.b             |
| └─Sort_11                      | 30000.00 | root      |                       | test.t._tidb_rowid             |
|   └─PartitionUnion_13          | 30000.00 | root      |                       |                                |
|     ├─TableReader_15           | 10000.00 | root      |                       | data:TableFullScan_14          |
|     │ └─TableFullScan_14       | 10000.00 | cop[tikv] | table:t, partition:p0 | keep order:false, stats:pseudo |
|     ├─TableReader_17           | 10000.00 | root      |                       | data:TableFullScan_16          |
|     │ └─TableFullScan_16       | 10000.00 | cop[tikv] | table:t, partition:p1 | keep order:false, stats:pseudo |
|     └─TableReader_19           | 10000.00 | root      |                       | data:TableFullScan_18          |
|       └─TableFullScan_18       | 10000.00 | cop[tikv] | table:t, partition:p2 | keep order:false, stats:pseudo |
+--------------------------------+----------+-----------+-----------------------+--------------------------------+
9 rows in set (0.00 sec)

MySQL [test]> drop table t;
Query OK, 0 rows affected (0.03 sec)

MySQL [test]> create table t(a int, b int);
Query OK, 0 rows affected (0.02 sec)

MySQL [test]> explain select * from t order by _tidb_rowid;
+--------------------------+----------+-----------+---------------+-------------------------------+
| id                       | estRows  | task      | access object | operator info                 |
+--------------------------+----------+-----------+---------------+-------------------------------+
| Projection_5             | 10000.00 | root      |               | test.t.a, test.t.b            |
| └─TableReader_11         | 10000.00 | root      |               | data:TableFullScan_10         |
|   └─TableFullScan_10     | 10000.00 | cop[tikv] | table:t       | keep order:true, stats:pseudo |
+--------------------------+----------+-----------+---------------+-------------------------------+
3 rows in set (0.00 sec)

Describe the feature you'd like:

For sort on partition tables, we can sort each partition first, and merge sort those ordered inputs. Then for each partition, it may be able to utilize an index to provide the required order. That would accelerate the execution a lot and reduce memory / cpu usages.

Describe alternatives you've considered:

No.

Teachability, Documentation, Adoption, Migration Strategy:

This can accelerate the execution a lot and reduce memory / cpu usages for TiDB. Besides, this kind of query is supposed to be common in backup tools, this feature would benefit them as well.

@eurekaka eurekaka added sig/planner SIG: Planner type/feature-request Categorizes issue or PR as related to a new feature. component/executor labels Jan 15, 2021
@zz-jason zz-jason removed the type/feature-request Categorizes issue or PR as related to a new feature. label Apr 21, 2021
@zz-jason
Copy link
Member

not a SQL feature request, moved it out of the feature-request kanban.

@mjonss
Copy link
Contributor

mjonss commented Feb 14, 2022

/component tablepartition

@ti-chi-bot ti-chi-bot added the component/tablepartition This issue is related to Table Partition of TiDB. label Feb 14, 2022
@Defined2014
Copy link
Contributor

I think we already supported it, ref link #26166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/executor component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner
Projects
None yet
Development

No branches or pull requests

5 participants