[
https://issues.apache.org/jira/browse/CALCITE-4058?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17136134#comment-17136134
]
Julian Hyde commented on CALCITE-4058:
--------------------------------------
Let's suppose we were to introduce a logical {{Limit}} operator. What fields
would it have? An instance of that operator needs to know how many rows to
fetch, and how to sort them. So your operator ends up with fields {{fetch}},
{{offset}}, {{collation}} - the exact same fields that {{Sort}} has today.
An alternative is to require the input to be sorted. Then the {{Limit}}
operator would only need {{fetch}} and {{offset}} fields. But now the operator
is only well-defined if the input is sorted. So it's no longer a logical
operator. (People have argued that the {{Window}} logical operator should
require its input to be sorted, and I believe that would be wrong, for similar
reasons.)
You can argue that {{Sort}} should be a separate operator because it is an
enforcer. That is appealing in a purist sense. But the cost is to add one extra
operator to our core set of operators. That is something we should not do
lightly. Increasing a matrix from size N to N+1 adds 2N to the number of
pairwise combinations.
Designing the right set of core logical operators is very much like the [RISC
vs
CISC|https://cs.stanford.edu/people/eroberts/courses/soco/projects/risc/risccisc]
debate in designing machine instructions. There is a design tension between
approaches. In this case, because of the similarity between {{Sort}} and
{{Limit}} at both logical and physical levels, we made a deliberate choice to
go a little towards the CISC side, combining them into one more powerful
operator, and managed to keep the number of operators down, a RISC-style
benefit.
> Add Limit and LogicalLimit operator and deprecate limit in Sort
> ---------------------------------------------------------------
>
> Key: CALCITE-4058
> URL: https://issues.apache.org/jira/browse/CALCITE-4058
> Project: Calcite
> Issue Type: New Feature
> Components: core
> Reporter: Haisheng Yuan
> Priority: Major
>
> Add {{Limit}} base class and {{LogicalLimit}} operator.
> Fetch and offset should not be in Sort operator, we should deprecate the
> fields while keeping the Sort work for compatibility.
> {code:java}
> select * from foo limit 5 offset 3;
> select * from foo order by a;
> {code}
> The above 2 queries are totally different query, but have the same operators,
> SortxxxTranspose sometimes means limit push down, which is counter-intuitive.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)