You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "suibianwanwan (Jira)" <ji...@apache.org> on 2025/02/05 12:37:00 UTC

[jira] [Comment Edited] (CALCITE-6652) RelDecorrelator can't decorrelate query with limit 1

    [ https://issues.apache.org/jira/browse/CALCITE-6652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17903855#comment-17903855 ] 

suibianwanwan edited comment on CALCITE-6652 at 2/5/25 12:36 PM:
-----------------------------------------------------------------

Hi, [~julianhyde]. As discussed in CALCITE-1317, we can't do a conversion between max and order by limit 1 when rowCount is empty.

Edit: 
in the decorrelate, we add correlated variables to the group list to ensure equivalence when Correlate is transformed to Join. When the group list is non-empty, MIN/MAX will also return 0 rows if input with 0 rows.(This behavior also leads to the issue described in [CALCITE-5743]). So if corVar exists, the conversion is valid.


was (Author: JIRAUSER301334):
Hi, [~julianhyde]. As discussed in CALCITE-1317, we can't do a conversion between max and order by limit 1 when rowCount is empty.

Edit: Sorry for doing too much editing, the logic here should be that the conversion is valid if a particular RelNode, for a row of 0 outputs the same result as a null row. One scenario is in a Filter where the condition satisfies Strong.isNotTrue()

> RelDecorrelator can't decorrelate query with limit 1
> ----------------------------------------------------
>
>                 Key: CALCITE-6652
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6652
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: suibianwanwan
>            Assignee: suibianwanwan
>            Priority: Major
>
> The following query can't decorrelate by RelDecorrelate:
> {code:java}
> @Test void testDecorrelateFetchOne1() {
>   final String query = "SELECT deptno FROM dept WHERE\n" +
>       "1000 > (SELECT sal FROM emp WHERE dept.deptno = emp.deptno order by emp.sal limit 1)";
>   sql(query).withRule(
>           CoreRules.FILTER_SUB_QUERY_TO_CORRELATE)
>       .withLateDecorrelate(true)
>       .check();
> }{code}
> is equivalent to the following query, and the following query can be decorrelated into a join, so we can do some appropriate conversions in RelDecorrelate:
> {code:java}
> @Test void testDecorrelateFetchOne1() {
>   final String query = "SELECT deptno FROM dept WHERE\n" +
>       "1000 > (SELECT min(sal) FROM emp WHERE dept.deptno = emp.deptno)";
>   sql(query).withRule(
>           CoreRules.FILTER_SUB_QUERY_TO_CORRELATE)
>       .withLateDecorrelate(true)
>       .check();
> }{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)