提交 cc28d22a authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

#299 Nested derrived tables did not always work as expected

上级 8b124771
......@@ -8,6 +8,7 @@ package org.h2.index;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;
import org.h2.api.ErrorCode;
import org.h2.command.Parser;
import org.h2.command.Prepared;
......@@ -314,7 +315,10 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
return q;
}
int firstIndexParam = view.getParameterOffset(originalParameters);
IntArray paramIndex = new IntArray();
// the column index of each parameter
// (for example: paramColumnIndex {0, 0} mean
// param[0] is column 0, and param[1] is also column 0)
IntArray paramColumnIndex = new IntArray();
int indexColumnCount = 0;
for (int i = 0; i < masks.length; i++) {
int mask = masks[i];
......@@ -322,16 +326,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
continue;
}
indexColumnCount++;
paramIndex.add(i);
if (Integer.bitCount(mask) > 1) {
// two parameters for range queries: >= x AND <= y
paramIndex.add(i);
// the number of parameters depends on the mask;
// for range queries it is 2: >= x AND <= y
// but bitMask could also be 7 (=, and <=, and >=)
int bitCount = Integer.bitCount(mask);
for (int j = 0; j < bitCount; j++) {
paramColumnIndex.add(i);
}
}
int len = paramIndex.size();
int len = paramColumnIndex.size();
ArrayList<Column> columnList = New.arrayList();
for (int i = 0; i < len;) {
int idx = paramIndex.get(i);
int idx = paramColumnIndex.get(i);
columnList.add(table.getColumn(idx));
int mask = masks[idx];
if ((mask & IndexCondition.EQUALITY) != 0) {
......
......@@ -34,6 +34,7 @@ public class TestView extends TestBase {
@Override
public void test() throws SQLException {
deleteDb("view");
testSubSubQuery();
testSubQueryViewIndexCache();
testInnerSelectWithRownum();
testInnerSelectWithRange();
......@@ -52,6 +53,19 @@ public class TestView extends TestBase {
deleteDb("view");
}
private void testSubSubQuery() throws SQLException {
Connection conn = getConnection("view");
Statement stat = conn.createStatement();
stat.execute("drop table test if exists");
stat.execute("create table test(a int, b int, c int)");
stat.execute("insert into test values(1, 1, 1)");
ResultSet rs = stat.executeQuery("select 1 x from (select a, b, c from " +
"(select * from test) bbb where bbb.a >=1 and bbb.a <= 1) sp " +
"where sp.a = 1 and sp.b = 1 and sp.c = 1");
assertTrue(rs.next());
conn.close();
}
private void testSubQueryViewIndexCache() throws SQLException {
if (config.networked) {
return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论