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

Register all combinations of materialization substitutions

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5.0
    • Component/s: None
    • Labels:

      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_2.patch
          18 kB
          Maryann Xue
        2. CALCITE-890_plus_3.patch
          22 kB
          Maryann Xue
        3. CALCITE-890_plus.patch
          21 kB
          Maryann Xue
        4. CALCITE-890.patch
          8 kB
          Maryann Xue

          Activity

            People

            • Assignee:
              maryannxue Maryann Xue
              Reporter:
              maryannxue Maryann Xue
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: