Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6746

Optimization rule ProjectWindowTranspose is unsound

    XMLWordPrintableJSON

Details

    Description

      Here is an an example plan before and after this rule:

          LogicalProject(EXPR$0=[CASE(>($3, 0), $4, null:INTEGER)], salary=[$0], enroll_date=[$1]), id = 630
            LogicalWindow(window#0=[window(order by [1] range between $2 PRECEDING and $2 FOLLOWING aggs [COUNT($0), $SUM0($0)])]), id = 628
              LogicalProject(salary=[$2], enroll_date=[$3], $2=[*(365, 86400000:INTERVAL DAY)]), id = 626
                LogicalTableScan(table=[[schema, empsalary]]), id = 592
      

      after:

          LogicalProject(EXPR$0=[CASE(>($2, 0), $3, null:INTEGER)], salary=[$0], enroll_date=[$1]), id = 645
            LogicalWindow(window#0=[window(order by [1] range between $2 PRECEDING and $2 FOLLOWING aggs [COUNT($0), $SUM0($0)])]), id = 643
              LogicalProject(salary=[$0], enroll_date=[$1]), id = 639
                LogicalProject(salary=[$2], enroll_date=[$3], $2=[*(365, 86400000:INTERVAL DAY)]), id = 633
                  LogicalTableScan(table=[[schema, empsalary]]), id = 592
      

      The problem is the representation of the window bound, which refers to field $2. After this optimization this field no longer exists in the project that is an input to the Window.

      I suspect that the problem is in the code ProjectWindowTransposeRule that maintains the beReferred bitset; it never adds the window bounds to this set.

      Attachments

        Issue Links

          Activity

            People

              mbudiu Mihai Budiu
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: