Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
Description
When a Sort represents 'Order By x Limit n',and its input is guaranteed that is at most one row,we could remove this Sort.
For example, the sql:
SELECT count(*) FROM orders ORDER BY 1 LIMIT 10
because the SELECT count(*) FROM orders row count is 1, it is at most one row, then we could remove ORDER BY 1 LIMIT 10; after the optimization, the sql is:
SELECT count(*) FROM orders
Above logic are same as Presto/Trino's RemoveRedundantTopN rule:
This JIRA is enhancement for CALCITE-5994; in 5994, we restrict Sort must be pure Order(Offset and Limit is null), but after this jira, this optimization could be applied to 'Order By x' Or 'Order By x Limit n'.
Attachments
Issue Links
- duplicates
-
CALCITE-3952 Improve SortRemoveRule to remove Sort based on rowcount
- Resolved
- is related to
-
CALCITE-5940 Add the Rule to merge Limit
- Closed
-
CALCITE-5994 Add optimization rule to remove Sort when its input's row number is less or equal to one
- Closed
- links to