Maryann Xue created CALCITE-890:
-----------------------------------
Summary: Register all combinations of materialization substitutions
Key: CALCITE-890
URL: https://issues.apache.org/jira/browse/CALCITE-890
Project: Calcite
Issue Type: Improvement
Reporter: Maryann Xue
Assignee: Julian Hyde
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.
{code}
@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);
}
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)