提交 52d3131d authored 作者: Thomas Mueller's avatar Thomas Mueller

In memory database: outer joins with a condition "column is null" could return the wrong result.

上级 d6f602e4
...@@ -768,9 +768,18 @@ public class Select extends Query { ...@@ -768,9 +768,18 @@ public class Select extends Query {
if (condition != null) { if (condition != null) {
condition = condition.optimize(session); condition = condition.optimize(session);
for (TableFilter f : filters) { for (TableFilter f : filters) {
// outer joins: must not add index conditions such as
// "c is null" - example:
// create table parent(p int primary key) as select 1;
// create table child(c int primary key, pc int);
// insert into child values(2, 1);
// select p, c from parent
// left outer join child on p = pc where c is null;
if (!f.isJoinOuter() && !f.isJoinOuterIndirect()) {
condition.createIndexConditions(session, f); condition.createIndexConditions(session, f);
} }
} }
}
if (isGroupQuery && groupIndex == null && havingIndex < 0 && filters.size() == 1) { if (isGroupQuery && groupIndex == null && havingIndex < 0 && filters.size() == 1) {
if (condition == null) { if (condition == null) {
ExpressionVisitor optimizable = ExpressionVisitor.get(ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL); ExpressionVisitor optimizable = ExpressionVisitor.get(ExpressionVisitor.OPTIMIZABLE_MIN_MAX_COUNT_ALL);
......
...@@ -36,6 +36,7 @@ public class TestCases extends TestBase { ...@@ -36,6 +36,7 @@ public class TestCases extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
testOuterJoin();
testColumnWithConstraintAndComment(); testColumnWithConstraintAndComment();
testTruncateConstraintsDisabled(); testTruncateConstraintsDisabled();
testPreparedSubquery2(); testPreparedSubquery2();
...@@ -83,6 +84,18 @@ public class TestCases extends TestBase { ...@@ -83,6 +84,18 @@ public class TestCases extends TestBase {
deleteDb("cases"); deleteDb("cases");
} }
private void testOuterJoin() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("create table parent(p int primary key) as select 1");
stat.execute("create table child(c int primary key, pc int) as select 2, 1");
ResultSet rs = stat.executeQuery("select * from parent left outer join child on p = pc where c is null");
assertFalse(rs.next());
stat.execute("drop all objects");
conn.close();
}
private void testColumnWithConstraintAndComment() throws SQLException { private void testColumnWithConstraintAndComment() throws SQLException {
if (config.memory) { if (config.memory) {
return; return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论