提交 ce1d452a authored 作者: tledkov's avatar tledkov

#1057, #1072 set neverLazy for subquery in nested joins

上级 f03f4781
......@@ -870,7 +870,7 @@ public class Select extends Query {
}
private void disableLazyForJoinSubqueries(TableFilter f) {
for (; f != null; f = f.getJoin()) {
for (; f != null; f = f.getJoin() != null ? f.getJoin() : f.getNestedJoin()) {
if (f.getTable().getTableType() == TableType.VIEW) {
ViewIndex idx = (ViewIndex) f.getIndex();
if (idx != null && idx.getQuery() != null) {
......
......@@ -51,6 +51,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
testSubqueryInJoin(stmt);
testSubqueryInJoinFirst(stmt);
testJoinTwoSubqueries(stmt);
testSubqueryInNestedJoin(stmt);
}
}
finally {
......@@ -90,11 +91,26 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
checkExecutionTime(stmt, sql);
}
private void testSubqueryInNestedJoin(Statement stmt) throws Exception {
String sql =
"SELECT COUNT (one.x) FROM one " +
"LEFT JOIN (SELECT 1 AS val_1) AS subq0 " +
"JOIN (SELECT y AS val FROM one WHERE y < 30) AS subq1 ON subq0.val_1 < subq1.val " +
"ON one.x = subq1.val " +
"WHERE one.x < 30";
checkExecutionTime(stmt, sql, 3000);
}
private void checkExecutionTime(Statement stmt, String sql) throws Exception {
checkExecutionTime(stmt, sql, ROWS);
}
/**
* Compare execution time when lazy execution mode is disabled and enabled.
* The execution time must be almost the same.
*/
private void checkExecutionTime(Statement stmt, String sql) throws Exception {
private void checkExecutionTime(Statement stmt, String sql, int expected) throws Exception {
long totalNotLazy = 0;
long totalLazy = 0;
......@@ -102,8 +118,8 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
int failCnt = 0;
for (int i = 0; i < FAIL_REPEATS; ++i) {
long tNotLazy = executeAndCheckResult(stmt, sql, false);
long tLazy = executeAndCheckResult(stmt, sql, true);
long tLazy = executeAndCheckResult(stmt, sql, true, expected);
long tNotLazy = executeAndCheckResult(stmt, sql, false, expected);
totalNotLazy += tNotLazy;
totalLazy += tLazy;
......@@ -127,7 +143,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
/**
* @return Time of the query execution.
*/
private long executeAndCheckResult(Statement stmt, String sql, boolean lazy) throws SQLException {
private long executeAndCheckResult(Statement stmt, String sql, boolean lazy, int expected) throws SQLException {
if (lazy) {
stmt.execute("SET LAZY_QUERY_EXECUTION 1");
}
......@@ -138,7 +154,7 @@ public class TestSubqueryPerformanceOnLazyExecutionMode extends TestDb {
long t0 = System.currentTimeMillis();
try (ResultSet rs = stmt.executeQuery(sql)) {
rs.next();
assertEquals(ROWS, rs.getInt(1));
assertEquals(expected, rs.getInt(1));
}
return System.currentTimeMillis() - t0;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论