[
https://issues.apache.org/jira/browse/CALCITE-1498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15685224#comment-15685224
]
Maryann Xue commented on CALCITE-1498:
--------------------------------------
Yes, neither the original subject nor the description was very clear. I will
change them according based on your version.
Right, they are not deterministic. But let's say OFFSET is actually the number
of rows we should skip before outputting the result. In those cases where the
result is not deterministic before applying OFFSET, it does not matter which
rows we skip but it does matter how many rows we will skip. Especially when the
number of rows before applying LIMIT is smaller than LIMIT itself, we could end
up returning less rows than we should. A left or right join can return one or
more rows for each row from the "outer" side, so if we push down OFFSET, it's
likely that we can skip more rows than we should.
> Allow LIMIT with trivial ORDER BY to be pushed through JOIN
> -----------------------------------------------------------
>
> Key: CALCITE-1498
> URL: https://issues.apache.org/jira/browse/CALCITE-1498
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.10.0
> Reporter: Maryann Xue
> Assignee: Maryann Xue
> Priority: Minor
>
> Allow LIMIT with trivial ORDER BY to be pushed through a JOIN that does not
> affect the number of rows. Currently it cannot, because
> {{RelMdUtil.checkInputForCollationAndLimit}} does not know that an sort on
> zero keys is trivially satisfied (without requiring a Sort) by any relational
> expression:
> {code}
> // Check if the input is already sorted
> boolean alreadySorted = false;
> if (!alreadySorted) {
> for (RelCollation inputCollation : mq.collations(input)) {
> if (inputCollation.satisfies(collation)) {
> alreadySorted = true;
> break;
> }
> }
> }
> {code}
> if {{mq.collations(input)}} returns an empty array, {{alreadySorted}} will
> always be false even if the required {{collation}} is an empty collation
> (which indicates there's no need to sort).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)