提交 54e6e45c authored 作者: Owner's avatar Owner

Testing localized fix for lazy eval and recursive

上级 978ff88f
......@@ -666,12 +666,12 @@ public class Select extends Query {
private boolean hasRecursiveTopTableView() {
//check the top table filter only to see if we have a recursive table query
if(this.topTableFilter.getTable().isTableExpression()){
TableView v = (TableView)this.topTableFilter.getTable();
if(v.isRecursive()){
return true;
}
}
// if(this.topTableFilter.getTable().isTableExpression()){
// TableView v = (TableView)this.topTableFilter.getTable();
// if(v.isRecursive()){
// return true;
// }
// }
return false;
}
......
......@@ -6,9 +6,9 @@
package org.h2.index;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;
import org.h2.api.ErrorCode;
import org.h2.command.Parser;
import org.h2.command.Prepared;
......@@ -182,16 +182,18 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
private Cursor findRecursive(SearchRow first, SearchRow last) {
assert recursive;
ResultInterface recResult = view.getRecursiveResult();
if (recResult != null) {
recResult.reset();
return new ViewCursor(this, recResult, first, last);
ResultInterface recursiveResult = view.getRecursiveResult();
if (recursiveResult != null) {
recursiveResult.reset();
//System.out.println("findRecursive.return ViewCursor=recResult="+recursiveResult+",first="+first+",last="+last);
return new ViewCursor(this, recursiveResult, first, last);
}
if (query == null) {
Parser parser = new Parser(createSession);
parser.setRightsChecked(true);
parser.setSuppliedParameterList(originalParameters);
query = (Query) parser.prepare(querySQL);
//System.out.println("findRecursive.querySQL="+querySQL);
query.setNeverLazy(true);
}
if (!query.isUnion()) {
......@@ -200,35 +202,43 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
}
SelectUnion union = (SelectUnion) query;
Query left = union.getLeft();
left.setNeverLazy(true);
// to ensure the last result is not closed
left.disableCache();
ResultInterface r = left.query(0);
LocalResult result = union.getEmptyResult();
ResultInterface resultInterface = left.query(0);
LocalResult localResult = 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());
localResult.setMaxMemoryRows(Integer.MAX_VALUE);
while (resultInterface.next()) {
Value[] cr = resultInterface.currentRow();
//System.out.println("findRecursive.while left resultinterface next row="+Arrays.toString(cr));
localResult.addRow(cr);
}
Query right = union.getRight();
r.reset();
view.setRecursiveResult(r);
right.setNeverLazy(true);
//System.out.println("right="+right.getSQL());
resultInterface.reset();
view.setRecursiveResult(resultInterface);
// to ensure the last result is not closed
right.disableCache();
while (true) {
r = right.query(0);
if (!r.hasNext()) {
resultInterface = right.query(0);
if (!resultInterface.hasNext()) {
//System.out.println("right query has no results");
break;
}
while (r.next()) {
result.addRow(r.currentRow());
while (resultInterface.next()) {
Value[] cr = resultInterface.currentRow();
//System.out.println("findRecursive.while right resultinterface next row="+Arrays.toString(cr));
localResult.addRow(cr);
}
r.reset();
view.setRecursiveResult(r);
resultInterface.reset();
view.setRecursiveResult(resultInterface);
}
view.setRecursiveResult(null);
result.done();
return new ViewCursor(this, result, first, last);
localResult.done();
return new ViewCursor(this, localResult, first, last);
}
/**
......
......@@ -540,9 +540,9 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
private void testSimple3RowRecursiveQueryWithLazyEval() throws Exception {
String[] expectedRowData =new String[]{"|1","|2","|3"};
String[] expectedColumnTypes =new String[]{"INTEGER"};
String[] expectedColumnNames =new String[]{"N"};
String[] expectedRowData =new String[]{"|6",};
String[] expectedColumnTypes =new String[]{"BIGINT"};
String[] expectedColumnNames =new String[]{"SUM(N)"};
// back up the config - to restore it after this test
TestAll backupConfig = config;
......@@ -558,10 +558,12 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
config.multiThreaded = true;
String SETUP_SQL = "--no config set";
String WITH_QUERY = "with recursive r(n) as (\n"+
"(select 1) union all (select n+1 from r where n < 3)\n"+
")\n"+
"select n from r";
String WITH_QUERY = "select sum(n) from (\n"
+" with recursive r(n) as (\n"
+" (select 1) union all (select n+1 from r where n < 3) \n"
+" )\n"
+" select n from r \n"
+")\n";
int maxRetries = 10;
int expectedNumberOfRows = expectedRowData.length;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论