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

Trim unused fields for plan of materialized-view before matching.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.21.0
    • Component/s: None

      Description

      In current code, before matching query with materialized-view, unused fields of query is trimmed but materialized-view is not. Thus below simple SQL fails to be matched though query and materialized-
      view are exactly the same:

      @Test public void testMaterializationAfterTrimingOfUnusedFields() {
      String sql =
      "select \"y\".\"deptno\", \"y\".\"name\", \"x\".\"sum_salary\"\n" +
      "from\n" +
      " (select \"deptno\", sum(\"salary\") \"sum_salary\" from \"emps\" group by \"deptno\") \"x\"\n" +
      " join\n" +
      " \"depts\" \"y\"\n" +
      " on \"x\".\"deptno\"=\"y\".\"deptno\"\n";
      checkMaterialize(sql, sql);
      }

       Checking CalciteMaterializer https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/prepare/CalciteMaterializer.java#L83 , I think the code intends to do the trimming, but didn't call the method.
      Since unused fields of query is trimmed anyway https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java#L995 , thus I think there's no necessity to keep the materialized-view un-trimmed

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                jinxing6042@126.com Jin Xing
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

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