提交 b011c858 authored 作者: noelgrandin's avatar noelgrandin

fix my previous commit, and add a unit test to cover that case

上级 00b69a6b
...@@ -172,12 +172,12 @@ public class ConditionAndOr extends Condition { ...@@ -172,12 +172,12 @@ public class ConditionAndOr extends Condition {
return added.optimize(session); return added.optimize(session);
} }
} else if (left instanceof ConditionInConstantSet && right instanceof Comparison) { } else if (left instanceof ConditionInConstantSet && right instanceof Comparison) {
Expression added = ((ConditionInConstantSet) left).getAdditional((Comparison) right); Expression added = ((ConditionInConstantSet) left).getAdditional(session, (Comparison) right);
if (added != null) { if (added != null) {
return added.optimize(session); return added.optimize(session);
} }
} else if (right instanceof ConditionInConstantSet && left instanceof Comparison) { } else if (right instanceof ConditionInConstantSet && left instanceof Comparison) {
Expression added = ((ConditionInConstantSet) right).getAdditional((Comparison) left); Expression added = ((ConditionInConstantSet) right).getAdditional(session, (Comparison) left);
if (added != null) { if (added != null) {
return added.optimize(session); return added.optimize(session);
} }
......
...@@ -139,10 +139,11 @@ public class ConditionInConstantSet extends Condition { ...@@ -139,10 +139,11 @@ public class ConditionInConstantSet extends Condition {
* @param other the second condition * @param other the second condition
* @return null if the condition was not added, or the new condition * @return null if the condition was not added, or the new condition
*/ */
Expression getAdditional(Comparison other) { Expression getAdditional(Session session, Comparison other) {
Expression add = other.getIfEquals(left); Expression add = other.getIfEquals(left);
if (add != null) { if (add != null) {
valueList.add(add); valueList.add(add);
valueSet.add(add.getValue(session).convertTo(left.getType()));
return this; return this;
} }
return null; return null;
......
...@@ -825,7 +825,9 @@ public class TestOptimizations extends TestBase { ...@@ -825,7 +825,9 @@ public class TestOptimizations extends TestBase {
rs.next(); rs.next();
assertContains(rs.getString(1), "ID IN(1, 2, 3, 4, 5)"); assertContains(rs.getString(1), "ID IN(1, 2, 3, 4, 5)");
stat.execute("DROP TABLE test"); rs = stat.executeQuery("SELECT COUNT(*) FROM test WHERE ID=1 OR ID=2 OR ID=3 OR ID=4 OR ID=5");
rs.next();
assertEquals(5, rs.getInt(1));
conn.close(); conn.close();
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论