pingcap/tidb

planner: Limit cannot be pushed down through IndexLookUp when the keep-order is true and it has a table-side Selection

Open

#21.250 aperta il 24 nov 2020

Vedi su GitHub
 (10 commenti) (0 reazioni) (2 assegnatari)Go (6186 fork)batch import
help wantedreport/customersig/plannertype/enhancement

Metriche repository

Star
 (40.090 star)
Metriche merge PR
 (Merge medio 14g 4h) (346 PR mergiate in 30 g)

Descrizione

Development Task

mysql> create table t (a int, b int, key(a));
mysql> explain select * from t where b>10 order by a limit 1;
+-----------------------------------+---------+-----------+---------------------+--------------------------------+
| id                                | estRows | task      | access object       | operator info                  |
+-----------------------------------+---------+-----------+---------------------+--------------------------------+
| Limit_12                          | 1.00    | root      |                     | offset:0, count:1              |
| └─Projection_25                   | 1.00    | root      |                     | test.t.a, test.t.b             |
|   └─IndexLookUp_24                | 1.00    | root      |                     |                                |
|     ├─IndexFullScan_21(Build)     | 3.00    | cop[tikv] | table:t, index:a(a) | keep order:true, stats:pseudo  |
|     └─Selection_23(Probe)         | 1.00    | cop[tikv] |                     | gt(test.t.b, 10)               |
|       └─TableRowIDScan_22         | 3.00    | cop[tikv] | table:t             | keep order:false, stats:pseudo |
+-----------------------------------+---------+-----------+---------------------+--------------------------------+

In the case above, we can push Limit down to the probe side to get a better plan:

Limit                           root
  Projection                    root
    IndexLookUp                 root
      IndexFullScan             cop
      Limit                     cop
        Selection               cop
           TableRowIDScan       cop

Guida contributor