pingcap / pingcap/tidb

the pushed down topN didn't collect the right output rows

Open
#64,838 2 comments 0 reactions 0 assignees View on GitHub
severity/minor sig/execution sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

```
create table t(a int, b int);
insert into t values(1,1),(2,2),(3,3);
insert into t select * from t; * N times
explain analyze select * from t order by b limit 2;
```

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

Image
the pushed-down topN should record the exact N rows just like limit did in actRows

### 3. What did you see instead (Required)
```
mysql> explain analyze select * from t order by b limit 2;
+----------------------------+-----------+---------+-----------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+-----------+---------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+----------------------------+-----------+---------+-----------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+-----------+---------+
| TopN_8 | 2.00 | 2 | root | | time:83.1ms, open:75.5µs, close:2.46µs, loops:2, RU:27.81 | test.t.b, offset:0, count:2 | 776 Bytes | 0 Bytes |
| └─TableReader_17 | 2.00 | 2 | root | | time:83.1ms, open:38µs, close:2.13µs, loops:2, cop_task: {num: 1, max: 83ms, proc_keys: 0, tot_proc: 82ms, copr_cache_hit_ratio: 0.00, build_task_duration: 12.3µs, max_distsql_concurrency: 1}, fetch_resp_duration: 83ms, rpc_info:{Cop:{num_rpc:1, total_time:83ms}} | data:TopN_16 | 254 Bytes | N/A |
| └─TopN_16 | 2.00 | 399360 | cop[tikv] | | tikv_task:{time:82.9ms, loops:0}, time_detail: {total_process_time: 82ms} | test.t.b, offset:0, count:2 | N/A | N/A |
| └─TableFullScan_15 | 399360.00 | 399360 | cop[tikv] | table:t | tikv_task:{time:82.9ms, loops:0} | keep order:false, stats:pseudo | N/A | N/A |
+----------------------------+-----------+---------+-----------+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+-----------+---------+
4 rows in set (0.087 sec)
mysql> mysql> explain analyze select * from t limit 2;
+----------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+-----------+------+
| id | estRows | actRows | task | access object | execution info | operator info | memory | disk |
+----------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+-----------+------+
| Limit_8 | 2.00 | 2 | root | | time:359.8µs, open:57.6µs, close:4.92µs, loops:2, RU:0.48 | offset:0, count:2 | N/A | N/A |
| └─TableReader_14 | 2.00 | 2 | root | | time:349.5µs, open:51µs, close:4.5µs, loops:1, cop_task: {num: 1, max: 255.2µs, proc_keys: 0, copr_cache_hit_ratio: 0.00, build_task_duration: 18.3µs, max_distsql_concurrency: 1}, fetch_resp_duration: 275.4µs, rpc_info:{Cop:{num_rpc:1, total_time:228.8µs}} | data:Limit_13 | 239 Bytes | N/A |
| └─Limit_13 | 2.00 | 2 | cop[tikv] | | tikv_task:{time:158.8µs, loops:0} | offset:0, count:2 | N/A | N/A |
| └─TableFullScan_12 | 2.00 | 64 | cop[tikv] | table:t | tikv_task:{time:158.8µs, loops:0} | keep order:false, stats:pseudo | N/A | N/A |
+----------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+-----------+------+
4 rows in set (0.002 sec)

```

### 4. What is your TiDB version? (Required)

master & next-gen

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.