You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "junheleo (Jira)" <ji...@apache.org> on 2023/06/02 09:47:00 UTC

[jira] [Updated] (CALCITE-5742) SubstitutionVisitor Causes Infinite Loop when using AggregateOnCalcToAggregateUnifyRule

     [ https://issues.apache.org/jira/browse/CALCITE-5742?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

junheleo updated CALCITE-5742:
------------------------------
    Description: 
Here is a simple code snippet to reproduce the issue:
{code:java}
// Test case in MaterializedViewSubstitutionVisitorTest

@Test void testAggregateOnProject6() {
  sql("select count(1) from (select \"empid\", \"deptno\", \"name\", count(*) from \"emps\""
          + "group by \"empid\", \"deptno\", \"name\" limit 10)  ",
      "select \"empid\", \"deptno\" from (select \"empid\", \"deptno\", \"name\", count(*) from \"emps\"\n"
          + "group by \"empid\", \"deptno\", \"name\" limit 10) group by \"empid\", \"deptno\"")
      .noMat();
}{code}
Canonicalized Query Plan:
{code:java}
-- Query Plan 
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 can not skip out because the condition "queryDescendant == r.after" is not met.

Thank you for your attention to this matter

 

  was:
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

 


> 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
>            Priority: Major
>
> Here is a simple code snippet to reproduce the issue:
> {code:java}
> // Test case in MaterializedViewSubstitutionVisitorTest
> @Test void testAggregateOnProject6() {
>   sql("select count(1) from (select \"empid\", \"deptno\", \"name\", count(*) from \"emps\""
>           + "group by \"empid\", \"deptno\", \"name\" limit 10)  ",
>       "select \"empid\", \"deptno\" from (select \"empid\", \"deptno\", \"name\", count(*) from \"emps\"\n"
>           + "group by \"empid\", \"deptno\", \"name\" limit 10) group by \"empid\", \"deptno\"")
>       .noMat();
> }{code}
> Canonicalized Query Plan:
> {code:java}
> -- Query Plan 
> 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 can not 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)