提交 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 { ...@@ -132,7 +132,12 @@ public class ConditionInSelect extends Condition {
buff.append(Comparison.getCompareOperator(compareType)). buff.append(Comparison.getCompareOperator(compareType)).
append(" ALL"); append(" ALL");
} else { } else {
if (compareType == Comparison.EQUAL) {
buff.append("IN"); buff.append("IN");
} else {
buff.append(Comparison.getCompareOperator(compareType)).
append(" ANY");
}
} }
buff.append("(\n").append(StringUtils.indent(query.getPlanSQL(), 4, false)). buff.append("(\n").append(StringUtils.indent(query.getPlanSQL(), 4, false)).
append("))"); append("))");
......
...@@ -115,7 +115,6 @@ public class TestCases extends TestBase { ...@@ -115,7 +115,6 @@ public class TestCases extends TestBase {
conn.close(); conn.close();
} }
private void testEmptyStatements() throws SQLException { private void testEmptyStatements() throws SQLException {
Connection conn = getConnection("cases"); Connection conn = getConnection("cases");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
......
...@@ -20,6 +20,7 @@ import org.h2.constant.ErrorCode; ...@@ -20,6 +20,7 @@ import org.h2.constant.ErrorCode;
import org.h2.test.TestBase; import org.h2.test.TestBase;
import org.h2.tools.SimpleResultSet; import org.h2.tools.SimpleResultSet;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.StringUtils;
import org.h2.util.Task; import org.h2.util.Task;
/** /**
...@@ -40,6 +41,7 @@ public class TestOptimizations extends TestBase { ...@@ -40,6 +41,7 @@ public class TestOptimizations extends TestBase {
@Override @Override
public void test() throws Exception { public void test() throws Exception {
deleteDb("optimizations"); deleteDb("optimizations");
testExplainRoundTrip();
testOrderByExpression(); testOrderByExpression();
testGroupSubquery(); testGroupSubquery();
testAnalyzeLob(); testAnalyzeLob();
...@@ -76,6 +78,26 @@ public class TestOptimizations extends TestBase { ...@@ -76,6 +78,26 @@ public class TestOptimizations extends TestBase {
deleteDb("optimizations"); 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 { private void testOrderByExpression() throws Exception {
Connection conn = getConnection("optimizations"); Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论