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); } }