提交 ab0708a7 authored 作者: Owner's avatar Owner

Testing recursive persistent cte's

上级 ca5acf41
...@@ -1086,46 +1086,47 @@ public class Select extends Query { ...@@ -1086,46 +1086,47 @@ public class Select extends Query {
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
for (TableFilter f : topFilters) { for (TableFilter f : topFilters) {
Table t = f.getTable(); Table t = f.getTable();
boolean isPersistent = !t.isTemporary();
if (t.isView() && ((TableView) t).isRecursive()) { if (t.isView() && ((TableView) t).isRecursive()) {
// hmmm - how do you generate a plan sql which is recursive continue;
// for a system which does not natively support recursive SQLs... ? // boolean isPersistent = !t.isTemporary();
// answer: you can't // // hmmm - how do you generate a plan sql which is recursive
TableView tv = ((TableView) t); // // for a system which does not natively support recursive SQLs... ?
buff.append("WITH "); // // answer: you can't
if(tv.isRecursive()){ // TableView tv = ((TableView) t);
buff.append("RECURSIVE "); // buff.append("WITH ");
} // if(tv.isRecursive()){
if(isPersistent){ // buff.append("RECURSIVE ");
buff.append("PERSISTENT "); // }
} // if(isPersistent){
buff.append(t.getName()).append('('); // buff.append("PERSISTENT ");
buff.resetCount(); // }
for (Column c : t.getColumns()) { // buff.append(t.getName()).append('(');
buff.appendExceptFirst(","); // buff.resetCount();
buff.append(c.getName()); // for (Column c : t.getColumns()) {
} // buff.appendExceptFirst(",");
String theSQL = t.getSQL(); // buff.append(c.getName());
System.out.println("getPlanSQL.theSQL="+theSQL); // }
System.out.println("getPlanSQL.sqlStatement="+sqlStatement); // String theSQL = t.getSQL();
if(!sqlStatement.contains("?") && sqlStatement.toUpperCase().contains("SELECT") && session.isParsingView()){ // System.out.println("getPlanSQL.theSQL="+theSQL);
theSQL = extractNamedCTEQueryFromSQL(t.getName(),sqlStatement); // System.out.println("getPlanSQL.sqlStatement="+sqlStatement);
if(!(theSQL.startsWith("(")&&theSQL.endsWith(")"))){ // if(!sqlStatement.contains("?") && sqlStatement.toUpperCase().contains("SELECT") && session.isParsingView()){
theSQL = "( "+theSQL+" )"; // theSQL = extractNamedCTEQueryFromSQL(t.getName(),sqlStatement);
} // if(!(theSQL.startsWith("(")&&theSQL.endsWith(")"))){
} // theSQL = "( "+theSQL+" )";
else if(!(theSQL.startsWith("(")&&theSQL.endsWith(")"))){ // }
StatementBuilder buffSelect = new StatementBuilder(); // }
buffSelect.append("( SELECT "); // else if(!(theSQL.startsWith("(")&&theSQL.endsWith(")"))){
buffSelect.resetCount(); // StatementBuilder buffSelect = new StatementBuilder();
for (Column c : t.getColumns()) { // buffSelect.append("( SELECT ");
buffSelect.appendExceptFirst(","); // buffSelect.resetCount();
buffSelect.append(c.getName()); // for (Column c : t.getColumns()) {
} // buffSelect.appendExceptFirst(",");
buffSelect.append(" FROM "+t.getSQL()+" ) "); // buffSelect.append(c.getName());
theSQL = buffSelect.toString(); // }
} // buffSelect.append(" FROM "+t.getSQL()+" ) ");
buff.append(") AS ").append(theSQL).append("\n"); // theSQL = buffSelect.toString();
// }
// buff.append(") AS ").append(theSQL).append("\n");
} }
} }
buff.resetCount(); buff.resetCount();
......
...@@ -1955,6 +1955,9 @@ public class Database implements DataHandler { ...@@ -1955,6 +1955,9 @@ public class Database implements DataHandler {
} }
System.out.println("Removing db object id - also remove meta lock from session and session lock from meta, id="+id+",sessionId="+session.getId()+",name="+savedName); System.out.println("Removing db object id - also remove meta lock from session and session lock from meta, id="+id+",sessionId="+session.getId()+",name="+savedName);
if("TREE_CTE".equals(savedName)){
new RuntimeException("TREE_CTE distruction").printStackTrace();
}
removeMeta(session, id); removeMeta(session, id);
flushDeferredRemoveSchemaObject(); flushDeferredRemoveSchemaObject();
......
...@@ -173,6 +173,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex { ...@@ -173,6 +173,7 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
Prepared p; Prepared p;
session.pushSubQueryInfo(masks, filters, filter, sortOrder); session.pushSubQueryInfo(masks, filters, filter, sortOrder);
try { try {
System.out.println("ViewIndex.prepareSubQuery:"+sql);
p = session.prepare(sql, true, true); p = session.prepare(sql, true, true);
} finally { } finally {
session.popSubQueryInfo(); session.popSubQueryInfo();
......
...@@ -571,7 +571,7 @@ public class TestGeneralCommonTableQueries extends TestBase { ...@@ -571,7 +571,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
String[] expectedColumnNames =new String[]{"SUB_TREE_ROOT_ID","TREE_LEVEL","PARENT_FK","CHILD_FK"}; String[] expectedColumnNames =new String[]{"SUB_TREE_ROOT_ID","TREE_LEVEL","PARENT_FK","CHILD_FK"};
int expectedNumberOfRows = 11; int expectedNumberOfRows = 11;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, SETUP_SQL, testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, SETUP_SQL,
WITH_QUERY, 0/*maxRetries-1*/); WITH_QUERY, maxRetries-1);
} }
private void testPersistentNonRecursiveTableInCreateView() throws Exception { private void testPersistentNonRecursiveTableInCreateView() throws Exception {
String SETUP_SQL = "" String SETUP_SQL = ""
...@@ -635,7 +635,7 @@ public class TestGeneralCommonTableQueries extends TestBase { ...@@ -635,7 +635,7 @@ public class TestGeneralCommonTableQueries extends TestBase {
conn = getConnection("commonTableExpressionQueries"); conn = getConnection("commonTableExpressionQueries");
} }
System.out.println("=========== test with query");
prep = conn.prepareStatement(WITH_QUERY); prep = conn.prepareStatement(WITH_QUERY);
rs = prep.executeQuery(); rs = prep.executeQuery();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论