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

Testing localized fix for lazy eval and recursive

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