提交 6047e2f4 authored 作者: Thomas Mueller's avatar Thomas Mueller

When used in a subquery, LIKE and IN(..) did not work correctly.

上级 8000a258
...@@ -153,12 +153,11 @@ public class ViewIndex extends BaseIndex { ...@@ -153,12 +153,11 @@ public class ViewIndex extends BaseIndex {
public Cursor find(Session session, SearchRow first, SearchRow last) throws SQLException { public Cursor find(Session session, SearchRow first, SearchRow last) throws SQLException {
ObjectArray paramList = query.getParameters(); ObjectArray paramList = query.getParameters();
int idx = 0;
for (int i = 0; originalParameters != null && i < originalParameters.size(); i++) { for (int i = 0; originalParameters != null && i < originalParameters.size(); i++) {
Parameter orig = (Parameter) originalParameters.get(i); Parameter orig = (Parameter) originalParameters.get(i);
int idx = orig.getIndex();
Parameter param = (Parameter) paramList.get(idx);
Value value = orig.getValue(session); Value value = orig.getValue(session);
idx = orig.getIndex();
Parameter param = (Parameter) paramList.get(idx++);
param.setValue(value); param.setValue(value);
} }
int len; int len;
...@@ -169,6 +168,7 @@ public class ViewIndex extends BaseIndex { ...@@ -169,6 +168,7 @@ public class ViewIndex extends BaseIndex {
} else { } else {
len = 0; len = 0;
} }
int idx = originalParameters == null ? 0 : originalParameters.size();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (first != null) { if (first != null) {
Value v = first.getValue(i); Value v = first.getValue(i);
...@@ -195,7 +195,7 @@ public class ViewIndex extends BaseIndex { ...@@ -195,7 +195,7 @@ public class ViewIndex extends BaseIndex {
if (masks == null) { if (masks == null) {
return query; return query;
} }
int firstIndexParam = query.getParameters().size(); int firstIndexParam = originalParameters == null ? 0 : originalParameters.size();
IntArray paramIndex = new IntArray(); IntArray paramIndex = new IntArray();
for (int i = 0; i < masks.length; i++) { for (int i = 0; i < masks.length; i++) {
int mask = masks[i]; int mask = masks[i];
......
...@@ -37,6 +37,7 @@ public class TestOptimizations extends TestBase { ...@@ -37,6 +37,7 @@ public class TestOptimizations extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
testNestedInSelectAndLike();
testInSelectJoin(); testInSelectJoin();
testMinMaxNullOptimization(); testMinMaxNullOptimization();
if (config.networked) { if (config.networked) {
...@@ -56,6 +57,20 @@ public class TestOptimizations extends TestBase { ...@@ -56,6 +57,20 @@ public class TestOptimizations extends TestBase {
deleteDb("optimizations"); deleteDb("optimizations");
} }
private void testNestedInSelectAndLike() throws SQLException {
deleteDb("optimizations");
Connection conn = getConnection("optimizations");
PreparedStatement prep;
prep = conn.prepareStatement("SELECT * FROM DUAL A WHERE A.X IN (SELECT B.X FROM DUAL B WHERE B.X LIKE ?)");
prep.setString(1, "1");
prep.execute();
prep = conn.prepareStatement("SELECT * FROM DUAL A WHERE A.X IN (SELECT B.X FROM DUAL B WHERE B.X IN (?, ?))");
prep.setInt(1, 1);
prep.setInt(2, 1);
prep.executeQuery();
conn.close();
}
private void testInSelectJoin() throws SQLException { private void testInSelectJoin() throws SQLException {
deleteDb("optimizations"); deleteDb("optimizations");
Connection conn = getConnection("optimizations"); Connection conn = getConnection("optimizations");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论