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

Testing recursive persistent cte's

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