提交 2604902d authored 作者: Alexander Paschenko's avatar Alexander Paschenko

Optimized column vs constant comparisons

上级 079c91bf
......@@ -194,6 +194,13 @@ public class Comparison extends Condition {
return ValueExpression.getNull();
}
}
int colType = left.getType();
int constType = r.getType();
int resType = Value.getHigherOrder(colType, constType);
// If not the column values will need to be promoted
// to constant type, but vise versa, then let's do this here once.
if (constType != resType)
right = ValueExpression.get(r.convertTo(resType));
} else if (right instanceof Parameter) {
((Parameter) right).setColumn(
((ExpressionColumn) left).getColumn());
......
......@@ -58,6 +58,7 @@ public class TestOptimizations extends TestBase {
testNestedIn();
testConstantIn1();
testConstantIn2();
testConstantTypeConversionToColumnType();
testNestedInSelectAndLike();
testNestedInSelect();
testInSelectJoin();
......@@ -463,6 +464,25 @@ public class TestOptimizations extends TestBase {
conn.close();
}
private void testConstantTypeConversionToColumnType() throws SQLException {
deleteDb("optimizations");
Connection conn = getConnection("optimizations;IGNORECASE=TRUE");
Statement stat = conn.createStatement();
stat.executeUpdate("CREATE TABLE test (x int)");
ResultSet resultSet;
resultSet = stat.executeQuery(
"EXPLAIN SELECT x FROM test WHERE x = '5'");
assertTrue(resultSet.next());
// String constant '5' has been converted to int constant 5 on optimization
assertTrue(resultSet.getString(1).endsWith("X = 5"));
stat.execute("drop table test");
conn.close();
}
private void testNestedInSelect() throws SQLException {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
......
......@@ -8172,9 +8172,9 @@ select * from s;
> rows: 1
select some(y>10), every(y>10), min(y), max(y) from t;
> BOOL_OR(Y > 10) BOOL_AND(Y > 10) MIN(Y) MAX(Y)
> --------------- ---------------- ------ ------
> null null null null
> BOOL_OR(Y > 10.0) BOOL_AND(Y > 10.0) MIN(Y) MAX(Y)
> ----------------- ------------------ ------ ------
> null null null null
> rows: 1
insert into t values(1000000004, 4);
......@@ -8230,9 +8230,9 @@ stddev_pop(distinct y) s_py, stddev_samp(distinct y) s_sy, var_pop(distinct y) v
> rows: 1
select some(y>10), every(y>10), min(y), max(y) from t;
> BOOL_OR(Y > 10) BOOL_AND(Y > 10) MIN(Y) MAX(Y)
> --------------- ---------------- ------ ------
> TRUE FALSE 4.0 16.0
> BOOL_OR(Y > 10.0) BOOL_AND(Y > 10.0) MIN(Y) MAX(Y)
> ----------------- ------------------ ------ ------
> TRUE FALSE 4.0 16.0
> rows: 1
drop view s;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论