提交 005714ec authored 作者: Owner's avatar Owner

Fixed SQL plan test errors for with statement

上级 b04995eb
...@@ -5389,7 +5389,7 @@ public class Parser { ...@@ -5389,7 +5389,7 @@ public class Parser {
synchronized(targetSession){ synchronized(targetSession){
view = new TableView(schema, id, cteViewName, querySQL, view = new TableView(schema, id, cteViewName, querySQL,
parameters, columnTemplateArray, targetSession, parameters, columnTemplateArray, targetSession,
allowRecursiveQueryDetection, false /* literalsChecked */, true /* isTableExpression */); allowRecursiveQueryDetection, false /* literalsChecked */, true /* isTableExpression */, isPersistent);
if (!view.isRecursiveQueryDetected() && allowRecursiveQueryDetection) { if (!view.isRecursiveQueryDetected() && allowRecursiveQueryDetection) {
if(isPersistent){ if(isPersistent){
db.addSchemaObject(targetSession, view); db.addSchemaObject(targetSession, view);
...@@ -5400,7 +5400,7 @@ public class Parser { ...@@ -5400,7 +5400,7 @@ public class Parser {
} }
view = new TableView(schema, id, cteViewName, querySQL, parameters, view = new TableView(schema, id, cteViewName, querySQL, parameters,
columnTemplateArray, targetSession, columnTemplateArray, targetSession,
false/* assume recursive */, false /* literalsChecked */, true /* isTableExpression */); false/* assume recursive */, false /* literalsChecked */, true /* isTableExpression */, isPersistent);
} }
} }
view.setTableExpression(true); view.setTableExpression(true);
......
...@@ -116,7 +116,7 @@ public class CreateView extends SchemaCommand { ...@@ -116,7 +116,7 @@ public class CreateView extends SchemaCommand {
} }
else else
{ {
view = new TableView(getSchema(), id, viewName, querySQL, null, columnTemplates, session, false/* allow recursive */, false/* literalsChecked */, isTableExpression); view = new TableView(getSchema(), id, viewName, querySQL, null, columnTemplates, session, false/* allow recursive */, false/* literalsChecked */, isTableExpression, true);
} }
} else { } else {
// TODO support isTableExpression in replace function... // TODO support isTableExpression in replace function...
......
...@@ -1086,47 +1086,21 @@ public class Select extends Query { ...@@ -1086,47 +1086,21 @@ 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();
if (t.isView() && ((TableView) t).isRecursive()) { TableView tableView = (t instanceof TableView) ? (TableView) t : null;
if (tableView!=null && tableView.isView() && tableView.isRecursive() && tableView.isTableExpression()) {
if(tableView.isPersistent()){
continue; continue;
// boolean isPersistent = !t.isTemporary(); }
// // hmmm - how do you generate a plan sql which is recursive else {
// // for a system which does not natively support recursive SQLs... ? buff.append("WITH RECURSIVE ").append(t.getName()).append('(');
// // answer: you can't buff.resetCount();
// TableView tv = ((TableView) t); for (Column c : t.getColumns()) {
// buff.append("WITH "); buff.appendExceptFirst(",");
// if(tv.isRecursive()){ buff.append(c.getName());
// buff.append("RECURSIVE "); }
// } buff.append(") AS ").append(t.getSQL()).append("\n");
// 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(); buff.resetCount();
......
...@@ -60,13 +60,13 @@ public class TableView extends Table { ...@@ -60,13 +60,13 @@ public class TableView extends Table {
private ResultInterface recursiveResult; private ResultInterface recursiveResult;
private boolean isRecursiveQueryDetected; private boolean isRecursiveQueryDetected;
private boolean isTableExpression; private boolean isTableExpression;
// private Session session; private boolean isPersistent;
public TableView(Schema schema, int id, String name, String querySQL, public TableView(Schema schema, int id, String name, String querySQL,
ArrayList<Parameter> params, Column[] columnTemplates, Session session, ArrayList<Parameter> params, Column[] columnTemplates, Session session,
boolean allowRecursive, boolean literalsChecked, boolean isTableExpression) { boolean allowRecursive, boolean literalsChecked, boolean isTableExpression, boolean isPersistent) {
super(schema, id, name, false, true); super(schema, id, name, false, true);
init(querySQL, params, columnTemplates, session, allowRecursive, literalsChecked, isTableExpression); init(querySQL, params, columnTemplates, session, allowRecursive, literalsChecked, isTableExpression, isPersistent);
} }
/** /**
...@@ -86,23 +86,25 @@ public class TableView extends Table { ...@@ -86,23 +86,25 @@ public class TableView extends Table {
init(querySQL, null, init(querySQL, null,
newColumnTemplates == null ? this.columnTemplates newColumnTemplates == null ? this.columnTemplates
: newColumnTemplates, : newColumnTemplates,
session, recursive, literalsChecked, isTableExpression); session, recursive, literalsChecked, isTableExpression, isPersistent);
DbException e = recompile(session, force, true); DbException e = recompile(session, force, true);
if (e != null) { if (e != null) {
init(oldQuerySQL, null, oldColumnTemplates, session, oldRecursive, init(oldQuerySQL, null, oldColumnTemplates, session, oldRecursive,
literalsChecked, isTableExpression); literalsChecked, isTableExpression, isPersistent);
recompile(session, true, false); recompile(session, true, false);
throw e; throw e;
} }
} }
private synchronized void init(String querySQL, ArrayList<Parameter> params, private synchronized void init(String querySQL, ArrayList<Parameter> params,
Column[] columnTemplates, Session session, boolean allowRecursive, boolean literalsChecked, boolean isTableExpression) { Column[] columnTemplates, Session session, boolean allowRecursive, boolean literalsChecked,
boolean isTableExpression, boolean isPersistent) {
this.querySQL = querySQL; this.querySQL = querySQL;
this.columnTemplates = columnTemplates; this.columnTemplates = columnTemplates;
this.allowRecursive = allowRecursive; this.allowRecursive = allowRecursive;
this.isRecursiveQueryDetected = false; this.isRecursiveQueryDetected = false;
this.isTableExpression = isTableExpression; this.isTableExpression = isTableExpression;
this.isPersistent = isPersistent;
//this.session = session; //this.session = session;
index = new ViewIndex(this, querySQL, params, allowRecursive); index = new ViewIndex(this, querySQL, params, allowRecursive);
initColumnsAndTables(session, literalsChecked); initColumnsAndTables(session, literalsChecked);
...@@ -550,7 +552,7 @@ public class TableView extends Table { ...@@ -550,7 +552,7 @@ public class TableView extends Table {
String querySQL = query.getPlanSQL(); String querySQL = query.getPlanSQL();
TableView v = new TableView(mainSchema, 0, name, TableView v = new TableView(mainSchema, 0, name,
querySQL, query.getParameters(), null, session, querySQL, query.getParameters(), null, session,
false, true /* literals have already been checked when parsing original query */, false); false, true /* literals have already been checked when parsing original query */, false, false/* is persistent*/);
if (v.createException != null) { if (v.createException != null) {
throw v.createException; throw v.createException;
} }
...@@ -712,7 +714,7 @@ public class TableView extends Table { ...@@ -712,7 +714,7 @@ public class TableView extends Table {
TableView view = new TableView(schema, id, name, querySQL, TableView view = new TableView(schema, id, name, querySQL,
parameters, columnTemplates, session, parameters, columnTemplates, session,
true/* try recursive */, literalsChecked, isTableExpression ); true/* try recursive */, literalsChecked, isTableExpression, isPersistent );
//System.out.println("create recursive view:"+view); //System.out.println("create recursive view:"+view);
//if(shadowTable!=null){ //if(shadowTable!=null){
...@@ -734,10 +736,14 @@ public class TableView extends Table { ...@@ -734,10 +736,14 @@ public class TableView extends Table {
} }
view = new TableView(schema, id, name, querySQL, parameters, view = new TableView(schema, id, name, querySQL, parameters,
columnTemplates, session, columnTemplates, session,
false/* detected not recursive */, literalsChecked, isTableExpression); false/* detected not recursive */, literalsChecked, isTableExpression, isPersistent);
//System.out.println("create nr view:"+view); //System.out.println("create nr view:"+view);
} }
return view; return view;
} }
public boolean isPersistent() {
return isPersistent;
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论