some adjacent limit is redundant and unnecessary
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
```
drop table if exists t;
create table t(a int primary key, b int);
insert into t values (1, 11), (4, 44), (2, 22), (3, 33);
set session tidb_executor_concurrency = 4;
set @@session.tidb_hash_join_concurrency = 5;
set @@session.tidb_distsql_scan_concurrency = 15;
mysql> explain select a from (select a from t where b > 2 order by a limit 3 offset 1) as t1 order by a limit 2 offset 1;
+--------------------------------+---------+-----------+---------------+-------------------------------+
| id | estRows | task | access object | operator info |
+--------------------------------+---------+-----------+---------------+-------------------------------+
| Limit_18 | 1.33 | root | | offset:1, count:2 |
| └─Limit_44 | 1.33 | root | | offset:1, count:3 |
| └─TableReader_49 | 1.33 | root | | data:Limit_48 |
| └─Limit_48 | 1.33 | cop[tikv] | | offset:0, count:4 |
| └─Selection_29 | 1.33 | cop[tikv] | | gt(test.t.b, 2) |
| └─TableFullScan_28 | 4.00 | cop[tikv] | table:t | keep order:true, stats:pseudo |
+--------------------------------+---------+-----------+---------------+-------------------------------+
6 rows in set (0.00 sec)
expected
Limit_24 2.00 root offset:2, count:2
└─TableReader_32 4.00 root data:Limit_33
└─Limit_33 4.00 cop[tikv] offset:0, count:4
└─Selection_30 4.00 cop[tikv] gt(planner__cascades__integration.t.b, 2)
└─TableFullScan_31 4.00 cop[tikv] table:t keep order:true, stats:pseudo
```
Contributor guide
Assessment
This issue has not been assessed yet.