提交 464c791c authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore: temporary tables from result sets could survive re-opening a database,…

MVStore: temporary tables from result sets could survive re-opening a database, which could result in a ClassCastException.
上级 0f74ce2d
......@@ -8,7 +8,7 @@ package org.h2.expression;
import org.h2.command.dml.Query;
import org.h2.engine.Session;
import org.h2.result.ResultInterface;
import org.h2.result.LocalResult;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.util.StringUtils;
......@@ -29,7 +29,7 @@ public class ConditionExists extends Condition {
@Override
public Value getValue(Session session) {
query.setSession(session);
ResultInterface result = query.query(1);
LocalResult result = query.query(1);
session.addTemporaryResult(result);
boolean r = result.getRowCount() > 0;
return ValueBoolean.get(r);
......
......@@ -44,6 +44,7 @@ public class ConditionInSelect extends Condition {
@Override
public Value getValue(Session session) {
query.setSession(session);
query.setDistinct(true);
LocalResult rows = query.query(0);
session.addTemporaryResult(rows);
Value l = left.getValue(session);
......
......@@ -7,7 +7,7 @@
package org.h2.index;
import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.result.LocalResult;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.table.Table;
......@@ -20,12 +20,12 @@ import org.h2.value.ValueNull;
public class ViewCursor implements Cursor {
private final Table table;
private final Index index;
private final ResultInterface result;
private final ViewIndex index;
private final LocalResult result;
private final SearchRow first, last;
private Row current;
ViewCursor(Index index, ResultInterface result, SearchRow first,
ViewCursor(ViewIndex index, LocalResult result, SearchRow first,
SearchRow last) {
this.table = index.getTable();
this.index = index;
......@@ -49,7 +49,11 @@ public class ViewCursor implements Cursor {
while (true) {
boolean res = result.next();
if (!res) {
result.close();
if (index.isRecursive()) {
result.reset();
} else {
result.close();
}
current = null;
return false;
}
......
......@@ -17,7 +17,6 @@ import org.h2.expression.Comparison;
import org.h2.expression.Parameter;
import org.h2.message.DbException;
import org.h2.result.LocalResult;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.SearchRow;
import org.h2.result.SortOrder;
......@@ -187,7 +186,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
private Cursor find(Session session, SearchRow first, SearchRow last,
SearchRow intersection) {
if (recursive) {
ResultInterface recResult = view.getRecursiveResult();
LocalResult recResult = view.getRecursiveResult();
if (recResult != null) {
recResult.reset();
return new ViewCursor(this, recResult, first, last);
......@@ -209,6 +208,9 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
left.disableCache();
LocalResult r = left.query(0);
LocalResult result = union.getEmptyResult();
// ensure it is not written to disk,
// because it is not closed normally
result.setMaxMemoryRows(Integer.MAX_VALUE);
while (r.next()) {
result.addRow(r.currentRow());
}
......@@ -280,7 +282,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
}
}
}
ResultInterface result = query.query(0);
LocalResult result = query.query(0);
return new ViewCursor(this, result, first, last);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论