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: the optimizer cannot choose the best IndexMerge plan #48359

Closed
qw4990 opened this issue Nov 7, 2023 · 1 comment · Fixed by #49632
Closed

planner: the optimizer cannot choose the best IndexMerge plan #48359

qw4990 opened this issue Nov 7, 2023 · 1 comment · Fixed by #49632
Assignees
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Nov 7, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> create table t (a int, b int, c int, key a(a), key b(b), key ac(a, c), key bc(b, c));
Query OK, 0 rows affected (0.02 sec)

mysql> explain format='verbose' select * from t where a=1 or b=1 order by c;
+----------------------------------+---------+---------+-----------+---------------------+---------------------------------------------+
| id                               | estRows | estCost | task      | access object       | operator info                               |
+----------------------------------+---------+---------+-----------+---------------------+---------------------------------------------+
| Sort_5                           | 19.99   | 5431.39 | root      |                     | test.t.c                                    |
| └─IndexMerge_14                  | 19.99   | 1019.04 | root      |                     | type: union                                 |
|   ├─IndexRangeScan_11(Build)     | 10.00   | 2035.00 | cop[tikv] | table:t, index:a(a) | range:[1,1], keep order:false, stats:pseudo |
|   ├─IndexRangeScan_12(Build)     | 10.00   | 2035.00 | cop[tikv] | table:t, index:b(b) | range:[1,1], keep order:false, stats:pseudo |
|   └─TableRowIDScan_13(Probe)     | 19.99   | 4881.56 | cop[tikv] | table:t             | keep order:false, stats:pseudo              |
+----------------------------------+---------+---------+-----------+---------------------+---------------------------------------------+
5 rows in set, 1 warning (0.00 sec)

mysql> explain format='verbose' select /*+ use_index_merge(t, ac, bc) */ * from t where a=1 or b=1 order by c;
+----------------------------------+---------+---------+-----------+-------------------------+--------------------------------------------+
| id                               | estRows | estCost | task      | access object           | operator info                              |
+----------------------------------+---------+---------+-----------+-------------------------+--------------------------------------------+
| Projection_17                    | 19.99   | 1225.69 | root      |                         | test.t.a, test.t.b, test.t.c               |
| └─IndexMerge_16                  | 19.99   | 1219.71 | root      |                         | type: union                                |
|   ├─IndexRangeScan_13(Build)     | 10.00   | 2273.08 | cop[tikv] | table:t, index:ac(a, c) | range:[1,1], keep order:true, stats:pseudo |
|   ├─IndexRangeScan_14(Build)     | 10.00   | 2273.08 | cop[tikv] | table:t, index:bc(b, c) | range:[1,1], keep order:true, stats:pseudo |
|   └─TableRowIDScan_15(Probe)     | 19.99   | 4881.56 | cop[tikv] | table:t                 | keep order:false, stats:pseudo             |
+----------------------------------+---------+---------+-----------+-------------------------+--------------------------------------------+
5 rows in set (0.00 sec)

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

It should choose the IndexMerge using ac + bc.

3. What did you see instead (Required)

It choose the IndexMerge using a + b

4. What is your TiDB version? (Required)

Git Commit Hash: ece2375df4ec70f57168a5e4e2fc4e420d3913e4
@qw4990 qw4990 added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner labels Nov 7, 2023
@ti-chi-bot ti-chi-bot bot added may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 labels Nov 8, 2023
@winoros
Copy link
Member

winoros commented Nov 14, 2023

We mark this issue's affect version starting from 7.1 ince the ORDER PROP's push-down is fully supported from 7.1

@winoros winoros added type/enhancement The issue or PR belongs to an enhancement. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. and removed type/bug The issue is confirmed as a bug. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 affects-7.1 This bug affects the 7.1.x(LTS) versions. labels Nov 14, 2023
@AilinKid AilinKid self-assigned this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants