junheleo created CALCITE-5742:
---------------------------------

             Summary: SubstitutionVisitor Causes Infinite Loop when using 
AggregateOnCalcToAggregateUnifyRule
                 Key: CALCITE-5742
                 URL: https://issues.apache.org/jira/browse/CALCITE-5742
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.34.0
            Reporter: junheleo


Here is a simple code snippet to reproduce the issue:

 
{code:java}
//代码占位符
@Test void testAggregateOnProject6() {
  sql("select count(1) from (select \"empid\", \"deptno\", \"name\", count(*) 
from \"emps\"\n"
          + "group by \"empid\", \"deptno\", \"name\" limit 10)  ",
      "select \"empid\" + \"deptno\", sum(\"empid\" + \"deptno\") from (select 
\"empid\", " +
          "\"deptno\" from (select \"empid\", \"deptno\", \"name\", count(*) 
from \"emps\"\n"
          + "group by \"empid\", \"deptno\", \"name\" limit 10) group by 
\"empid\", \"deptno\" limit 5) group by  \"empid\" + \"deptno\"")
      .noMat();
} {code}
Canonicalized Query Plan:

 
{code:java}
-- Query Plan
LogicalAggregate(group=[{0}], EXPR$1=[SUM($0)])
  LogicalCalc(expr#0..1=[{inputs}], expr#2=[+($t0, $t1)], 0=[$t2])
    LogicalSort(fetch=[5])
      LogicalAggregate(group=[{0, 1}])
        LogicalCalc(expr#0..3=[{inputs}], proj#0..1=[{exprs}])
          LogicalSort(fetch=[10])
            LogicalAggregate(group=[{0, 1, 2}], EXPR$3=[COUNT()])
              LogicalCalc(expr#0..4=[{inputs}], proj#0..2=[{exprs}])
                LogicalTableScan(table=[[hr, emps]]) {code}
Canonicalized Target Plan

 
{code:java}
-- Target Plan
LogicalAggregate(group=[{}], EXPR$0=[COUNT()])
  LogicalSort(fetch=[10])
    LogicalAggregate(group=[{0, 1, 2}], EXPR$3=[COUNT()])
      LogicalCalc(expr#0..4=[{inputs}], proj#0..2=[{exprs}])
        LogicalTableScan(table=[[hr, emps]]) {code}
The input of Calc Under Aggregate was changed when executing permute in 
AggregateOnCalcToAggregateUnifyRule, then Visitor cann't skip out because the 
condition "queryDescendant == r.after" is not met.

Thank you for your attention to this matter

 



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

Reply via email to