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

Register all combinations of materialization substitutions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.5.0
    • None

    Description

      When a query has multiple table references, there could be:
      1) Multiple combinations of substituted Rels if one materialization is applicable for more than one sub-tree.
      2) Multiple combinations of substituted Rels if different materializations are applicable for different sub-trees respectively.

        @Test public void testSingleMaterializationMultiUsage() {
          String q = "select *\n"
              + "from (select * from \"emps\" where \"empid\" < 300)\n"
              + "join (select * from \"emps\" where \"empid\" < 200) using (\"empid\")";
          try {
            Prepare.THREAD_TRIM.set(true);
            MaterializationService.setThreadLocal();
            CalciteAssert.that()
                .withMaterializations(JdbcTest.HR_MODEL, 
                    "m0", "select * from \"emps\" where \"empid\" < 500")              
                .query(q)
                .enableMaterializations(true)
                .explainMatches("", new Function<ResultSet, Void>() {
                  public Void apply(ResultSet s) {
                    try {
                      final String actual = Util.toLinux(CalciteAssert.toString(s));
                      final String scan = "EnumerableTableScan(table=[[hr, m0]])";
                      assertTrue(actual + " should have had two occurrences of " + scan, 
                          StringUtils.countMatches(actual, scan) == 2);
                      return null;
                    } catch (SQLException e) {
                      throw new RuntimeException(e);
                    }
                  }
                })
                .sameResultWithMaterializationsDisabled();
          } finally {
            Prepare.THREAD_TRIM.set(false);
          }
        }
      
        @Test public void testMultiMaterializationMultiUsage() {
          String q = "select *\n"
              + "from (select * from \"emps\" where \"empid\" < 300)\n"
              + "join (select * from \"emps\" where \"deptno\" < 10) using (\"empid\")";
          try {
            Prepare.THREAD_TRIM.set(true);
            MaterializationService.setThreadLocal();
            CalciteAssert.that()
                .withMaterializations(JdbcTest.HR_MODEL, 
                    "m0", "select * from \"emps\" where \"empid\" < 500",
                    "m1", "select * from \"emps\" where \"deptno\" < 20")              
                .query(q)
                .enableMaterializations(true)
                .explainContains("EnumerableTableScan(table=[[hr, m0]])")
                .explainContains("EnumerableTableScan(table=[[hr, m1]])")
                .sameResultWithMaterializationsDisabled();
          } finally {
            Prepare.THREAD_TRIM.set(false);
          }
        }
      

      Attachments

        1. CALCITE-890_plus_3.patch
          22 kB
          Wei Xue
        2. CALCITE-890_plus_2.patch
          18 kB
          Wei Xue
        3. CALCITE-890_plus.patch
          21 kB
          Wei Xue
        4. CALCITE-890.patch
          8 kB
          Wei Xue

        Activity

          People

            maryannxue Wei Xue
            maryannxue Wei Xue
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: