kramerul commented on code in PR #3562:
URL: https://github.com/apache/calcite/pull/3562#discussion_r1923185937
##########
core/src/test/java/org/apache/calcite/test/JdbcAdapterTest.java:
##########
@@ -1424,6 +1430,57 @@ private LockWrapper exclusiveCleanDb(Connection c)
throws SQLException {
+ "GROUP BY \"t2\".\"DNAME\", \"t2\".\"DNAME0\"")
.runs();
}
+
+ /**
+ * Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-4188">[CALCITE-4188]
+ * Support EnumerableBatchNestedLoopJoin for JDBC</a>. */
+ @Test void testBatchNestedLoopJoinPlan() {
+ final String sql = "SELECT *\n"
+ + "FROM \"s\".\"emps\" A\n"
+ + "LEFT OUTER JOIN \"foodmart\".\"store\" B ON A.\"empid\" =
B.\"store_id\"";
+ final String explain = "JdbcFilter(condition=[OR(=($cor0.empid0, $0),
=($cor1.empid0, $0)";
+ final String jdbcSql = "SELECT *\n"
+ + "FROM \"foodmart\".\"store\"\n"
+ + "WHERE ? = \"store_id\" OR (? = \"store_id\" OR ? = \"store_id\") OR
(? = \"store_id\" OR"
+ + " (? = \"store_id\" OR ? = \"store_id\")) OR (? = \"store_id\" OR (?
= \"store_id\" OR ? "
+ + "= \"store_id\") OR (? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\"))) OR (? ="
+ + " \"store_id\" OR (? = \"store_id\" OR ? = \"store_id\") OR (? =
\"store_id\" OR (? = "
+ + "\"store_id\" OR ? = \"store_id\")) OR (? = \"store_id\" OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\") OR (? = \"store_id\" OR ? = \"store_id\" OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\")))) OR (? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\") OR (? = "
+ + "\"store_id\" OR (? = \"store_id\" OR ? = \"store_id\")) OR (? =
\"store_id\" OR (? = "
+ + "\"store_id\" OR ? = \"store_id\") OR (? = \"store_id\" OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\"))) OR (? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\") OR (? = "
+ + "\"store_id\" OR (? = \"store_id\" OR ? = \"store_id\")) OR (? =
\"store_id\" OR (? = "
+ + "\"store_id\" OR ? = \"store_id\") OR (? = \"store_id\" OR ? =
\"store_id\" OR (? = "
+ + "\"store_id\" OR ? = \"store_id\"))))) OR (? = \"store_id\" OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\") OR (? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\")) OR (? = "
+ + "\"store_id\" OR (? = \"store_id\" OR ? = \"store_id\") OR (? =
\"store_id\" OR (? = "
+ + "\"store_id\" OR ? = \"store_id\"))) OR (? = \"store_id\" OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\") OR (? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\")) OR (? = "
+ + "\"store_id\" OR (? = \"store_id\" OR ? = \"store_id\") OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\" OR (? = \"store_id\" OR ? = \"store_id\")))) OR (? =
\"store_id\" OR (? = "
+ + "\"store_id\" OR ? = \"store_id\") OR (? = \"store_id\" OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\")) OR (? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\") OR (? = "
+ + "\"store_id\" OR (? = \"store_id\" OR ? = \"store_id\"))) OR (? =
\"store_id\" OR (? = "
+ + "\"store_id\" OR ? = \"store_id\") OR (? = \"store_id\" OR (? =
\"store_id\" OR ? = "
+ + "\"store_id\")) OR (? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\") OR (? = "
+ + "\"store_id\" OR ? = \"store_id\" OR (? = \"store_id\" OR ? =
\"store_id\"))))))";
+ CalciteAssert.model(FoodmartSchema.FOODMART_MODEL)
+ .withSchema("s", new ReflectiveSchema(new HrSchema()))
+ .withHook(Hook.PLANNER, (Consumer<RelOptPlanner>) planner -> {
+
planner.addRule(EnumerableRules.ENUMERABLE_BATCH_NESTED_LOOP_JOIN_RULE);
+ })
+ .query(sql)
+ .explainContains(explain)
+ .runs()
+ .enable(CalciteAssert.DB == CalciteAssert.DatabaseInstance.HSQLDB
+ || CalciteAssert.DB == DatabaseInstance.POSTGRESQL)
+ .planHasSql(jdbcSql)
+ .returnsCount(4);
+ }
Review Comment:
This will not work. If the 2 nested correlated subqueries are both located
in a JDBC datasource, the planner will choose a normal SQL join because this
will produce less costs.
If one of the 2 correlated subqueries is not located in a JDBC datasource,
the test will not produce additional test coverage for this feature.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]