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

CalcReduceExpressionsRule may transform to same rel

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • None
    • None
    • server

    Description

      Method CalcReduceExpressionsRule#onMatch enters the branch and calculates reduceExpressions() condition. If that one is true it creates new calc. Unfortunately logic in reduceExpressions() is different then in the rest of the method and it can create a calc that is equal to the input.

      Example query SELECT floor(this / 1) FROM test.

      Input calc contains program with exprs:

      0 = {RexInputRef@11348} "$0"
      1 = {RexInputRef@11349} "$1"
      2 = {RexCall@11350} "CAST($t1):BIGINT(32)"
      3 = {RexLiteral@11351} "1:BIGINT(32)"
      4 = {RexCall@11352} "/($t2, $t3)"
      5 = {RexCall@11353} "FLOOR($t4)"

      The one on index 4 can be simplified (the division can be removed). That condition is met in reduceExpressions(),  but following logic in onMatch() doesn't simplify that expression. 

      This makes the output calc equals to input one which breaks the rest of query optimizing.

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              krzysztof.slusarski Krzysztof Ślusarski
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m