提交 fb146f24 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Move some common fields from Select and SelectUnion to Query

上级 ac05e08c
...@@ -10,6 +10,7 @@ import java.util.HashSet; ...@@ -10,6 +10,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Mode.ModeEnum; import org.h2.engine.Mode.ModeEnum;
...@@ -39,40 +40,56 @@ import org.h2.value.ValueNull; ...@@ -39,40 +40,56 @@ import org.h2.value.ValueNull;
*/ */
public abstract class Query extends Prepared { public abstract class Query extends Prepared {
/**
* The column list, including invisible expressions such as order by expressions.
*/
ArrayList<Expression> expressions;
/**
* Array of expressions.
*
* @see #expressions
*/
Expression[] expressionArray;
ArrayList<SelectOrderBy> orderList;
SortOrder sort;
/** /**
* The limit expression as specified in the LIMIT or TOP clause. * The limit expression as specified in the LIMIT or TOP clause.
*/ */
protected Expression limitExpr; Expression limitExpr;
/** /**
* Whether limit expression specifies percentage of rows. * Whether limit expression specifies percentage of rows.
*/ */
protected boolean fetchPercent; boolean fetchPercent;
/** /**
* Whether tied rows should be included in result too. * Whether tied rows should be included in result too.
*/ */
protected boolean withTies; boolean withTies;
/** /**
* The offset expression as specified in the LIMIT .. OFFSET clause. * The offset expression as specified in the LIMIT .. OFFSET clause.
*/ */
protected Expression offsetExpr; Expression offsetExpr;
/** /**
* The sample size expression as specified in the SAMPLE_SIZE clause. * The sample size expression as specified in the SAMPLE_SIZE clause.
*/ */
protected Expression sampleSizeExpr; Expression sampleSizeExpr;
/** /**
* Whether the result must only contain distinct rows. * Whether the result must only contain distinct rows.
*/ */
protected boolean distinct; boolean distinct;
/** /**
* Whether the result needs to support random access. * Whether the result needs to support random access.
*/ */
protected boolean randomAccessResult; boolean randomAccessResult;
private boolean noCache; private boolean noCache;
private int lastLimit; private int lastLimit;
...@@ -144,7 +161,9 @@ public abstract class Query extends Prepared { ...@@ -144,7 +161,9 @@ public abstract class Query extends Prepared {
* *
* @return the list of expressions * @return the list of expressions
*/ */
public abstract ArrayList<Expression> getExpressions(); public ArrayList<Expression> getExpressions() {
return expressions;
}
/** /**
* Calculate the cost to execute this query. * Calculate the cost to execute this query.
...@@ -178,14 +197,18 @@ public abstract class Query extends Prepared { ...@@ -178,14 +197,18 @@ public abstract class Query extends Prepared {
* *
* @param order the order by list * @param order the order by list
*/ */
public abstract void setOrder(ArrayList<SelectOrderBy> order); public void setOrder(ArrayList<SelectOrderBy> order) {
orderList = order;
}
/** /**
* Whether the query has an order. * Whether the query has an order.
* *
* @return true if it has * @return true if it has
*/ */
public abstract boolean hasOrder(); public boolean hasOrder() {
return orderList != null || sort != null;
}
/** /**
* Set the 'for update' flag. * Set the 'for update' flag.
...@@ -600,6 +623,11 @@ public abstract class Query extends Prepared { ...@@ -600,6 +623,11 @@ public abstract class Query extends Prepared {
return new SortOrder(session.getDatabase(), index, sortType, orderList); return new SortOrder(session.getDatabase(), index, sortType, orderList);
} }
@Override
public int getType() {
return CommandInterface.SELECT;
}
public void setOffset(Expression offset) { public void setOffset(Expression offset) {
this.offsetExpr = offset; this.offsetExpr = offset;
} }
......
...@@ -13,7 +13,6 @@ import java.util.HashSet; ...@@ -13,7 +13,6 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -76,12 +75,6 @@ public class Select extends Query { ...@@ -76,12 +75,6 @@ public class Select extends Query {
private final ArrayList<TableFilter> filters = Utils.newSmallArrayList(); private final ArrayList<TableFilter> filters = Utils.newSmallArrayList();
private final ArrayList<TableFilter> topFilters = Utils.newSmallArrayList(); private final ArrayList<TableFilter> topFilters = Utils.newSmallArrayList();
/**
* The column list, including synthetic columns (columns not shown in the
* result).
*/
ArrayList<Expression> expressions;
private Expression[] expressionArray;
private Expression having; private Expression having;
private Expression condition; private Expression condition;
...@@ -98,7 +91,6 @@ public class Select extends Query { ...@@ -98,7 +91,6 @@ public class Select extends Query {
private int[] distinctIndexes; private int[] distinctIndexes;
private int distinctColumnCount; private int distinctColumnCount;
private ArrayList<SelectOrderBy> orderList;
private ArrayList<Expression> group; private ArrayList<Expression> group;
/** /**
...@@ -136,7 +128,6 @@ public class Select extends Query { ...@@ -136,7 +128,6 @@ public class Select extends Query {
private boolean isQuickAggregateQuery, isDistinctQuery; private boolean isQuickAggregateQuery, isDistinctQuery;
private boolean isPrepared, checkInit; private boolean isPrepared, checkInit;
private boolean sortUsingIndex; private boolean sortUsingIndex;
private SortOrder sort;
/** /**
* The id of the current group. * The id of the current group.
...@@ -245,16 +236,6 @@ public class Select extends Query { ...@@ -245,16 +236,6 @@ public class Select extends Query {
return currentGroupRowId; return currentGroupRowId;
} }
@Override
public void setOrder(ArrayList<SelectOrderBy> order) {
orderList = order;
}
@Override
public boolean hasOrder() {
return orderList != null || sort != null;
}
@Override @Override
public void setDistinct() { public void setDistinct() {
if (distinctExpressions != null) { if (distinctExpressions != null) {
...@@ -1452,11 +1433,6 @@ public class Select extends Query { ...@@ -1452,11 +1433,6 @@ public class Select extends Query {
return topTableFilter; return topTableFilter;
} }
@Override
public ArrayList<Expression> getExpressions() {
return expressions;
}
@Override @Override
public void setForUpdate(boolean b) { public void setForUpdate(boolean b) {
this.isForUpdate = b; this.isForUpdate = b;
...@@ -1617,11 +1593,6 @@ public class Select extends Query { ...@@ -1617,11 +1593,6 @@ public class Select extends Query {
return !isForUpdate; return !isForUpdate;
} }
@Override
public int getType() {
return CommandInterface.SELECT;
}
@Override @Override
public boolean allowGlobalConditions() { public boolean allowGlobalConditions() {
return offsetExpr == null && (limitExpr == null || sort == null); return offsetExpr == null && (limitExpr == null || sort == null);
......
...@@ -9,7 +9,6 @@ import java.util.ArrayList; ...@@ -9,7 +9,6 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.command.CommandInterface;
import org.h2.engine.Mode; import org.h2.engine.Mode;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
...@@ -23,7 +22,6 @@ import org.h2.result.LazyResult; ...@@ -23,7 +22,6 @@ import org.h2.result.LazyResult;
import org.h2.result.LocalResult; import org.h2.result.LocalResult;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
import org.h2.result.ResultTarget; import org.h2.result.ResultTarget;
import org.h2.result.SortOrder;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.ColumnResolver; import org.h2.table.ColumnResolver;
import org.h2.table.Table; import org.h2.table.Table;
...@@ -73,10 +71,6 @@ public class SelectUnion extends Query { ...@@ -73,10 +71,6 @@ public class SelectUnion extends Query {
*/ */
final Query right; final Query right;
private ArrayList<Expression> expressions;
private Expression[] expressionArray;
private ArrayList<SelectOrderBy> orderList;
private SortOrder sort;
private boolean isPrepared, checkInit; private boolean isPrepared, checkInit;
private boolean isForUpdate; private boolean isForUpdate;
...@@ -110,21 +104,6 @@ public class SelectUnion extends Query { ...@@ -110,21 +104,6 @@ public class SelectUnion extends Query {
return right; return right;
} }
@Override
public void setSQL(String sql) {
this.sqlStatement = sql;
}
@Override
public void setOrder(ArrayList<SelectOrderBy> order) {
orderList = order;
}
@Override
public boolean hasOrder() {
return orderList != null || sort != null;
}
@Override @Override
public void setDistinctIfPossible() { public void setDistinctIfPossible() {
setDistinct(); setDistinct();
...@@ -376,11 +355,6 @@ public class SelectUnion extends Query { ...@@ -376,11 +355,6 @@ public class SelectUnion extends Query {
return set; return set;
} }
@Override
public ArrayList<Expression> getExpressions() {
return expressions;
}
@Override @Override
public void setForUpdate(boolean forUpdate) { public void setForUpdate(boolean forUpdate) {
left.setForUpdate(forUpdate); left.setForUpdate(forUpdate);
...@@ -484,11 +458,6 @@ public class SelectUnion extends Query { ...@@ -484,11 +458,6 @@ public class SelectUnion extends Query {
right.fireBeforeSelectTriggers(); right.fireBeforeSelectTriggers();
} }
@Override
public int getType() {
return CommandInterface.SELECT;
}
@Override @Override
public boolean allowGlobalConditions() { public boolean allowGlobalConditions() {
return left.allowGlobalConditions() && right.allowGlobalConditions(); return left.allowGlobalConditions() && right.allowGlobalConditions();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论