Skip to content

Adjust the estimated row count when push Limit and keep order for partitioned table #40986

@time-and-fate

Description

@time-and-fate

Enhancement

When there's a Limit above a scan operator, we should adjust the estimated row count of the scan operator accordingly.

But when we push Limit and keep order for a partitioned table (introduced in #36108 as a temporary enhancement), we didn't do this:

use test;
create table t (a int, b int, c int, index ia(a)) partition by range(b) (partition p1 values less than(100), partition p2 values less than(200), partition p3 values less than maxvalue);
analyze table t;
explain select a from t where a > 10 order by a limit 10;
+-----------------------------+---------+-----------+----------------------+-------------------------------------------------+
| id                          | estRows | task      | access object        | operator info                                   |
+-----------------------------+---------+-----------+----------------------+-------------------------------------------------+
| TopN_8                      | 10.00   | root      |                      | test.t.a, offset:0, count:10                    |
| └─IndexReader_15            | 10.00   | root      | partition:all        | index:Limit_14                                  |
|   └─Limit_14                | 10.00   | cop[tikv] |                      | offset:0, count:10                              |
|     └─IndexRangeScan_13     | 3333.33 | cop[tikv] | table:t, index:ia(a) | range:(10,+inf], keep order:false, stats:pseudo |
+-----------------------------+---------+-----------+----------------------+-------------------------------------------------+

Normally, if it's not a partitioned table, the estimated row count is like this:

use test;
create table t1 (a int, b int, c int, index ia(a));
analyze table t1;
explain select a from t1 order by a limit 10;
+----------------------------+---------+-----------+-----------------------+-------------------------------+
| id                         | estRows | task      | access object         | operator info                 |
+----------------------------+---------+-----------+-----------------------+-------------------------------+
| Limit_10                   | 10.00   | root      |                       | offset:0, count:10            |
| └─IndexReader_18           | 10.00   | root      |                       | index:Limit_17                |
|   └─Limit_17               | 10.00   | cop[tikv] |                       | offset:0, count:10            |
|     └─IndexFullScan_16     | 10.00   | cop[tikv] | table:t1, index:ia(a) | keep order:true, stats:pseudo |
+----------------------------+---------+-----------+-----------------------+-------------------------------+

Metadata

Metadata

Assignees

Labels

sig/plannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions