Unverified 提交 f68ac3f3 authored 作者: Andrei Tokar's avatar Andrei Tokar 提交者: GitHub

Merge pull request #1337 from h2database/value-comparison

Streamline Value comparison
......@@ -271,7 +271,10 @@ public class Comparison extends Condition {
return ValueNull.INSTANCE;
}
}
int dataType = Value.getHigherOrder(left.getType(), right.getType());
int leftType = left.getType();
int rightType = right.getType();
if (leftType != rightType || leftType == Value.ENUM) {
int dataType = Value.getHigherOrder(leftType, rightType);
if (dataType == Value.ENUM) {
String[] enumerators = ValueEnum.getEnumeratorsForBinaryOperation(l, r);
l = l.convertToEnum(enumerators);
......@@ -281,6 +284,7 @@ public class Comparison extends Condition {
l = l.convertTo(dataType, -1, mode);
r = r.convertTo(dataType, -1, mode);
}
}
boolean result = compareNotNull(database, l, r, compareType);
return ValueBoolean.get(result);
}
......
......@@ -142,22 +142,15 @@ public class ValueDataType implements DataType {
if (a == b) {
return 0;
}
// null is never stored;
// comparison with null is used to retrieve all entries
// in which case null is always lower than all entries
// (even for descending ordered indexes)
if (a == null) {
return -1;
} else if (b == null) {
return 1;
}
boolean aNull = a == ValueNull.INSTANCE;
boolean bNull = b == ValueNull.INSTANCE;
if (aNull || bNull) {
if (aNull || b == ValueNull.INSTANCE) {
return SortOrder.compareNull(aNull, sortType);
}
int t2 = Value.getHigherOrder(a.getType(), b.getType());
int aType = a.getType();
int bType = b.getType();
if (aType != bType || aType == Value.ENUM) {
int t2 = Value.getHigherOrder(aType, bType);
if (t2 == Value.ENUM) {
String[] enumerators = ValueEnum.getEnumeratorsForBinaryOperation(a, b);
a = a.convertToEnum(enumerators);
......@@ -166,6 +159,7 @@ public class ValueDataType implements DataType {
a = a.convertTo(t2, -1, mode);
b = b.convertTo(t2, -1, mode);
}
}
int comp = a.compareTypeSafe(b, compareMode);
if ((sortType & SortOrder.DESCENDING) != 0) {
......
......@@ -1213,7 +1213,10 @@ public abstract class Table extends SchemaObjectBase {
if (a == b) {
return 0;
}
int dataType = Value.getHigherOrder(a.getType(), b.getType());
int aType = a.getType();
int bType = b.getType();
if (aType != bType || aType == Value.ENUM) {
int dataType = Value.getHigherOrder(aType, bType);
if (dataType == Value.ENUM) {
String[] enumerators = ValueEnum.getEnumeratorsForBinaryOperation(a, b);
a = a.convertToEnum(enumerators);
......@@ -1223,6 +1226,7 @@ public abstract class Table extends SchemaObjectBase {
a = a.convertTo(dataType, -1, mode);
b = b.convertTo(dataType, -1, mode);
}
}
return a.compareTypeSafe(b, compareMode);
}
......
......@@ -1161,13 +1161,6 @@ public abstract class Value {
* 1 otherwise
*/
public final int compareTypeSafe(Value v, CompareMode mode) {
if (this == v) {
return 0;
} else if (this == ValueNull.INSTANCE) {
return -1;
} else if (v == ValueNull.INSTANCE) {
return 1;
}
return compareSecure(v, mode);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论