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

LIKE didn't use an index unless the right hand side was a literal or parameter.…

LIKE didn't use an index unless the right hand side was a literal or parameter. Now an index is used for LIKE CONCAT(?, '%').
上级 9f13c572
......@@ -157,14 +157,14 @@ public class CompareLike extends Condition {
return;
}
// parameters are always evaluatable, but
// we need to check the actual value now
// we need to check if the value is set
// (at prepare time)
// otherwise we would need to prepare at execute time,
// which is maybe slower (but maybe not in this case!)
if (!right.isValueSet()) {
// which may be slower (possibly not in this case)
if (!right.isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)) {
return;
}
if (escape != null && !escape.isValueSet()) {
if (escape != null && !escape.isEverything(ExpressionVisitor.INDEPENDENT_VISITOR)) {
return;
}
String p = right.getValue(session).getString();
......
......@@ -38,6 +38,7 @@ public class TestOptimizations extends TestBase {
public void test() throws Exception {
deleteDb("optimizations");
testLike();
testExistsSubquery();
testQueryCacheConcurrentUse();
testQueryCacheResetParams();
......@@ -67,6 +68,18 @@ public class TestOptimizations extends TestBase {
deleteDb("optimizations");
}
private void testLike() throws Exception {
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
stat.execute("create table test(name varchar primary key) as select x from system_range(1, 10)");
ResultSet rs = stat.executeQuery("explain select * from test where name like ? || '%' {1: 'Hello'}");
rs.next();
// ensure the ID = 10 part is evaluated first
assertContains(rs.getString(1), "PRIMARY_KEY_");
stat.execute("drop table test");
conn.close();
}
private void testExistsSubquery() throws Exception {
Connection conn = getConnection("optimizations");
Statement stat = conn.createStatement();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论