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

Improve test coverage, remove unnecessary code.

上级 33cf7b9d
...@@ -37,6 +37,13 @@ public class ConditionIn extends Condition { ...@@ -37,6 +37,13 @@ public class ConditionIn extends Condition {
private Value min, max; private Value min, max;
private int queryLevel; private int queryLevel;
/**
* Create a new IN(..) condition.
*
* @param database the database
* @param left the expression before IN
* @param values the value list (at least one element)
*/
public ConditionIn(Database database, Expression left, ObjectArray<Expression> values) { public ConditionIn(Database database, Expression left, ObjectArray<Expression> values) {
this.database = database; this.database = database;
this.left = left; this.left = left;
...@@ -45,9 +52,6 @@ public class ConditionIn extends Condition { ...@@ -45,9 +52,6 @@ public class ConditionIn extends Condition {
public Value getValue(Session session) throws SQLException { public Value getValue(Session session) throws SQLException {
Value l = left.getValue(session); Value l = left.getValue(session);
if (valueList.size() == 0) {
return ValueBoolean.get(false);
}
if (l == ValueNull.INSTANCE) { if (l == ValueNull.INSTANCE) {
return l; return l;
} }
...@@ -80,9 +84,6 @@ public class ConditionIn extends Condition { ...@@ -80,9 +84,6 @@ public class ConditionIn extends Condition {
} }
public Expression optimize(Session session) throws SQLException { public Expression optimize(Session session) throws SQLException {
if (valueList.size() == 0) {
return ValueExpression.get(ValueBoolean.get(false));
}
left = left.optimize(session); left = left.optimize(session);
boolean constant = left.isConstant(); boolean constant = left.isConstant();
if (constant && left == ValueExpression.getNull()) { if (constant && left == ValueExpression.getNull()) {
...@@ -152,6 +153,7 @@ public class ConditionIn extends Condition { ...@@ -152,6 +153,7 @@ public class ConditionIn extends Condition {
} }
} }
filter.addIndexCondition(IndexCondition.getInList(l, valueList)); filter.addIndexCondition(IndexCondition.getInList(l, valueList));
return;
} }
if (!SysProperties.OPTIMIZE_IN) { if (!SysProperties.OPTIMIZE_IN) {
return; return;
......
...@@ -460,11 +460,20 @@ public class TestOptimizations extends TestBase { ...@@ -460,11 +460,20 @@ public class TestOptimizations extends TestBase {
deleteDb("optimizations"); deleteDb("optimizations");
Connection conn = getConnection("optimizations"); Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
PreparedStatement prep;
ResultSet rs;
assertFalse(stat.executeQuery("select * from dual where x in()").next());
assertFalse(stat.executeQuery("select * from dual where null in(1)").next());
assertFalse(stat.executeQuery("select * from dual where null in(null)").next());
assertFalse(stat.executeQuery("select * from dual where null in(null, 1)").next());
assertFalse(stat.executeQuery("select * from dual where 1+x in(3, 4)").next());
assertFalse(stat.executeQuery("select * from dual d1, dual d2 where d1.x in(3, 4)").next());
stat.execute("create table test(id int primary key, name varchar)"); stat.execute("create table test(id int primary key, name varchar)");
stat.execute("insert into test values(1, 'Hello')"); stat.execute("insert into test values(1, 'Hello')");
stat.execute("insert into test values(2, 'World')"); stat.execute("insert into test values(2, 'World')");
PreparedStatement prep;
ResultSet rs;
prep = conn.prepareStatement("select * from test t1 where t1.id in(?)"); prep = conn.prepareStatement("select * from test t1 where t1.id in(?)");
prep.setInt(1, 1); prep.setInt(1, 1);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论