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

Views and derived tables with equality and range conditions on the same columns…

Views and derived tables with equality and range conditions on the same columns did not work properly. example: select x from (select x from (select 1 as x) where x > 0 and x < 2) where x = 1
上级 96b6d760
...@@ -255,30 +255,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex { ...@@ -255,30 +255,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
int idx = originalParameters == null ? 0 : originalParameters.size(); int idx = originalParameters == null ? 0 : originalParameters.size();
idx += view.getParameterOffset(); idx += view.getParameterOffset();
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
if (first != null) {
Value v = first.getValue(i);
if (v != null) {
int x = idx++;
setParameter(paramList, x, v);
}
}
if (last != null) {
int mask = indexMasks[i]; int mask = indexMasks[i];
// for equality, only one parameter is used (first == last) if ((mask & IndexCondition.EQUALITY) != 0) {
if (mask != IndexCondition.EQUALITY) { setParameter(paramList, idx++, first.getValue(i));
Value v = last.getValue(i);
if (v != null) {
int x = idx++;
setParameter(paramList, x, v);
}
} }
if ((mask & IndexCondition.START) != 0) {
setParameter(paramList, idx++, first.getValue(i));
} }
if (intersection != null) { if ((mask & IndexCondition.END) != 0) {
Value v = intersection.getValue(i); setParameter(paramList, idx++, last.getValue(i));
if (v != null) {
int x = idx++;
setParameter(paramList, x, v);
} }
if ((mask & IndexCondition.SPATIAL_INTERSECTS) != 0) {
setParameter(paramList, idx++, intersection.getValue(i));
} }
} }
LocalResult result = query.query(0); LocalResult result = query.query(0);
......
...@@ -32,6 +32,7 @@ public class TestView extends TestBase { ...@@ -32,6 +32,7 @@ public class TestView extends TestBase {
@Override @Override
public void test() throws SQLException { public void test() throws SQLException {
testInnerSelectWithRange();
testEmptyColumn(); testEmptyColumn();
testChangeSchemaSearchPath(); testChangeSchemaSearchPath();
testParameterizedView(); testParameterizedView();
...@@ -47,6 +48,24 @@ public class TestView extends TestBase { ...@@ -47,6 +48,24 @@ public class TestView extends TestBase {
deleteDb("view"); deleteDb("view");
} }
private void testInnerSelectWithRange() throws SQLException {
Connection conn = getConnection("view");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(
"select x from (select x from (" +
"select x from system_range(1, 5)) " +
"where x > 2 and x < 4) where x = 3");
assertTrue(rs.next());
assertFalse(rs.next());
rs = stat.executeQuery(
"select x from (select x from (" +
"select x from system_range(1, 5)) " +
"where x = 3) where x > 2 and x < 4");
assertTrue(rs.next());
assertFalse(rs.next());
conn.close();
}
private void testEmptyColumn() throws SQLException { private void testEmptyColumn() throws SQLException {
deleteDb("view"); deleteDb("view");
Connection conn = getConnection("view"); Connection conn = getConnection("view");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论