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

Optimize IN(...) queries: there was a bug in version 1.3.170 if the type of the…

Optimize IN(...) queries: there was a bug in version 1.3.170 if the type of the left hand side didn't match the type of the right hand side.
上级 abbbfc78
......@@ -80,10 +80,8 @@ public class ConditionIn extends Condition {
return left;
}
boolean allValuesConstant = true;
boolean allValuesSameType = true;
boolean allValuesNull = true;
int size = valueList.size();
Expression lastExpr = null;
for (int i = 0; i < size; i++) {
Expression e = valueList.get(i);
e = e.optimize(session);
......@@ -94,10 +92,6 @@ public class ConditionIn extends Condition {
allValuesConstant = false;
}
valueList.set(i, e);
if (lastExpr != null && lastExpr.getType() != e.getType()) {
allValuesSameType = false;
}
lastExpr = e;
}
if (constant && allValuesConstant) {
return ValueExpression.get(getValue(session));
......@@ -108,7 +102,11 @@ public class ConditionIn extends Condition {
expr = expr.optimize(session);
return expr;
}
if (allValuesConstant && allValuesSameType && !allValuesNull) {
if (allValuesConstant && !allValuesNull) {
int leftType = left.getType();
if (leftType == Value.UNKNOWN) {
return this;
}
Expression expr = new ConditionInConstantSet(session, left, valueList);
expr = expr.optimize(session);
return expr;
......
......@@ -43,29 +43,18 @@ public class ConditionInConstantSet extends Condition {
this.left = left;
this.valueList = valueList;
this.valueSet = new HashSet<Value>(valueList.size());
int type = left.getType();
for (Expression expression : valueList) {
valueSet.add(expression.getValue(session));
valueSet.add(expression.getValue(session).convertTo(type));
}
}
public Value getValue(Session session) {
Value leftVal = left.getValue(session);
if (leftVal == ValueNull.INSTANCE) {
return leftVal;
Value x = left.getValue(session);
if (x == ValueNull.INSTANCE) {
return x;
}
int todoFix;
Value firstRightValue = null;
for (Value v : valueSet) {
if (v != ValueNull.INSTANCE) {
firstRightValue = v;
break;
}
}
if (firstRightValue == null) {
throw DbException.throwInternalError();
}
leftVal = leftVal.convertTo(firstRightValue.getType());
boolean result = valueSet.contains(leftVal);
boolean result = valueSet.contains(x);
if (!result) {
boolean setHasNull = valueSet.contains(ValueNull.INSTANCE);
if (setHasNull) {
......
--- special grammar and test cases ---------------------------------------------------------------------------------------------
select * from dual where cast('a' || x as varchar_ignorecase) in ('A1', 'B1');
> X
> -
> 1
> rows: 1
create sequence seq start with 65 increment by 1;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论