提交 fbd2814e authored 作者: Thomas Mueller's avatar Thomas Mueller

EXPLAIN was incorrect for queries with "ANY" or "SOME" conditions.

上级 8f915d26
......@@ -132,7 +132,12 @@ public class ConditionInSelect extends Condition {
buff.append(Comparison.getCompareOperator(compareType)).
append(" ALL");
} else {
buff.append("IN");
if (compareType == Comparison.EQUAL) {
buff.append("IN");
} else {
buff.append(Comparison.getCompareOperator(compareType)).
append(" ANY");
}
}
buff.append("(\n").append(StringUtils.indent(query.getPlanSQL(), 4, false)).
append("))");
......
......@@ -115,7 +115,6 @@ public class TestCases extends TestBase {
conn.close();
}
private void testEmptyStatements() throws SQLException {
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
......
......@@ -20,6 +20,7 @@ import org.h2.constant.ErrorCode;
import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet;
import org.h2.util.New;
import org.h2.util.StringUtils;
import org.h2.util.Task;
/**
......@@ -40,6 +41,7 @@ public class TestOptimizations extends TestBase {
@Override
public void test() throws Exception {
deleteDb("optimizations");
testExplainRoundTrip();
testOrderByExpression();
testGroupSubquery();
testAnalyzeLob();
......@@ -75,6 +77,26 @@ public class TestOptimizations extends TestBase {
testConvertOrToIn();
deleteDb("optimizations");
}
private void testExplainRoundTrip() throws Exception {
Connection conn = getConnection("optimizations");
assertExplainRoundTrip(conn, "select x from dual where x > any(select x from dual)");
conn.close();
}
private void assertExplainRoundTrip(Connection conn, String sql) throws SQLException {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("explain " + sql);
rs.next();
String plan = rs.getString(1).toLowerCase();
plan = plan.replaceAll("\\s+", " ");
plan = plan.replaceAll("/\\*[^\\*]*\\*/", "");
plan = plan.replaceAll("\\s+", " ");
plan = StringUtils.replaceAll(plan, "system_range(1, 1)", "dual");
plan = plan.replaceAll("\\( ", "\\(");
plan = plan.replaceAll(" \\)", "\\)");
assertEquals(plan, sql);
}
private void testOrderByExpression() throws Exception {
Connection conn = getConnection("optimizations");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论