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

Planner push down TopN through IndexMerge #41028

Closed
fixdb opened this issue Feb 3, 2023 · 1 comment
Closed

Planner push down TopN through IndexMerge #41028

fixdb opened this issue Feb 3, 2023 · 1 comment
Labels
affects-6.5 sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@fixdb
Copy link
Contributor

fixdb commented Feb 3, 2023

Enhancement

create table foo(a int primary key, b int, c int, d int, e int);
create index index_bda on foo(b,d,a);
create index index_cda on foo(c,d,a);

explain select * from foo where b=10 or c=10 order by d desc limit 10;
+----------------------------------+---------+-----------+-------------------------------------+-----------------------------------------------+
| id                               | estRows | task      | access object                       | operator info                                 |
+----------------------------------+---------+-----------+-------------------------------------+-----------------------------------------------+
| TopN_10                          | 10.00   | root      |                                     | test.foo.d:desc, offset:0, count:10           |
| └─IndexMerge_25                  | 19.99   | root      |                                     | type: union                                   |
|   ├─IndexRangeScan_22(Build)     | 10.00   | cop[tikv] | table:foo, index:index_bda(b, d, a) | range:[10,10], keep order:false, stats:pseudo |
|   ├─IndexRangeScan_23(Build)     | 10.00   | cop[tikv] | table:foo, index:index_cda(c, d, a) | range:[10,10], keep order:false, stats:pseudo |
|   └─TableRowIDScan_24(Probe)     | 19.99   | cop[tikv] | table:foo                           | keep order:false, stats:pseudo                |
+----------------------------------+---------+-----------+-------------------------------------+-----------------------------------------------+
5 rows in set (0.01 sec)

Without IndexMerge, we can push TopN down to TiKV:

explain select * from foo where b=10 order by d desc limit 10;
+--------------------------------+---------+-----------+-------------------------------------+----------------------------------------------------+
| id                             | estRows | task      | access object                       | operator info                                      |
+--------------------------------+---------+-----------+-------------------------------------+----------------------------------------------------+
| IndexLookUp_24                 | 10.00   | root      |                                     | limit embedded(offset:0, count:10)                 |
| ├─Limit_23(Build)              | 10.00   | cop[tikv] |                                     | offset:0, count:10                                 |
| │ └─IndexRangeScan_21          | 10.00   | cop[tikv] | table:foo, index:index_bda(b, d, a) | range:[10,10], keep order:true, desc, stats:pseudo |
| └─TableRowIDScan_22(Probe)     | 10.00   | cop[tikv] | table:foo                           | keep order:false, stats:pseudo                     |
+--------------------------------+---------+-----------+-------------------------------------+----------------------------------------------------+
4 rows in set (0.00 sec)
@fixdb fixdb added the type/enhancement The issue or PR belongs to an enhancement. label Feb 3, 2023
ti-chi-bot bot pushed a commit that referenced this issue Aug 1, 2023
@jebter jebter added the sig/planner SIG: Planner label Sep 11, 2023
@winoros
Copy link
Member

winoros commented Sep 13, 2023

The basic needs of this issue have been solved. Closed this one.
The later improvements will be tracked by other issues.

@winoros winoros closed this as completed Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

6 participants