pingcap / pingcap/tidb

UnionAll should be able to reserve the order property comming from its children

Open
#59,869 1 comment 2 reactions 0 assignees View on GitHub
report/customer sig/execution sig/planner type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement

suppose that we have table
```
create table t(a int, index idx(a));
```

and a SQL `select * from (select a from t union all select a from t) t order by a limit 1`.

The best plan is that we keep the order property by reading index `idx` of table t and the union can also use the order property to perform a merge sort to output the data. In this way, we don't need any extra sort to sort the data can directly perform limit upon the union all.

current TiDB lacks the functionality and will do a sort after the union all. no rewrite can achieve the best possible plan until the union all can do the merge sort.

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.