Roman Churganov created CALCITE-6983:
----------------------------------------

             Summary: SortJoinTransposeRule should not push SORT past a UNION 
when SORT's fetch is DynamicParam
                 Key: CALCITE-6983
                 URL: https://issues.apache.org/jira/browse/CALCITE-6983
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.37.0
            Reporter: Roman Churganov
             Fix For: 1.39.0


A query like 
{code:sql}
           SELECT x.c11 FROM ( 
                     SELECT tt1.c11 FROM (
                                   SELECT c11 FROM sch1.foo as cp1 LIMIT ?
                     ) AS tt1 
                     UNION ALL
                     SELECT tt2.c11 FROM (
                                   SELECT c11 FROM sch1.foo as cp2 LIMIT ?
                      ) AS tt2
            ) AS x    LIMIT ?  
{code}
hangs on building  a plan, with debug log, can see a growing plans with a 
nested LogicalSort nodes, eventually it fails with StackOverflow..., 
{noformat}
       .....
LogicalSort(fetch=[?2])
  LogicalSort(subset=[rel#3740:RelSubset#269.NONE.[]], fetch=[?2])
    LogicalSort(subset=[rel#3670:RelSubset#264.NONE.[]], fetch=[?2])
      LogicalSort(subset=[rel#3600:RelSubset#259.NONE.[]], fetch=[?2])
        LogicalSort(subset=[rel#3530:RelSubset#254.NONE.[]], fetch=[?2])
          LogicalSort(subset=[rel#3460:RelSubset#249.NONE.[]], fetch=[?2])
            LogicalSort(subset=[rel#3390:RelSubset#244.NONE.[]], fetch=[?2])
              LogicalSort(subset=[rel#3320:RelSubset#239.NONE.[]], fetch=[?2])
                LogicalSort(subset=[rel#3250:RelSubset#234.NONE.[]], fetch=[?2])
                  LogicalSort(subset=[rel#3180:RelSubset#229.NONE.[]], 
fetch=[?2])
                    LogicalSort(subset=[rel#3110:RelSubset#224.NONE.[]], 
fetch=[?2])
                      LogicalSort(subset=[rel#3040:RelSubset#219.NONE.[]], 
fetch=[?2])
        ... 
{noformat}
Seem like an issue with  `SortUnionTransposeRule ` 




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

Reply via email to