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

Fixed SQL plan test errors for with statement

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