Package org.h2.expression
Class ExpressionVisitor
- java.lang.Object
-
- org.h2.expression.ExpressionVisitor
-
public final class ExpressionVisitor extends java.lang.ObjectThe visitor pattern is used to iterate through all expressions of a query to optimize a statement.
-
-
Field Summary
Fields Modifier and Type Field Description private static intCACHEDCount of cached INDEPENDENT and EVALUATABLE visitors with different query level.private AllColumnsForPlancolumns1static intDECREMENT_QUERY_LEVELDecrement query level of all expression columns.static intDETERMINISTICDoes the expression return the same results for the same parameters?static ExpressionVisitorDETERMINISTIC_VISITORThe visitor singleton for the type DETERMINISTIC.static intEVALUATABLECan the expression be evaluated, that means are all columns set to 'evaluatable'?static ExpressionVisitorEVALUATABLE_VISITORThe visitor singleton for the type EVALUATABLE.private static ExpressionVisitor[]EVALUATABLE_VISITORSEVALUATABLE listeners with query level 0, 1, ...static intGET_COLUMNS1Get all referenced columns for the optimiser.static intGET_COLUMNS2Get all referenced columns.static intGET_DEPENDENCIESRequest to get the set of dependencies (addDependency).static intINDEPENDENTIs the value independent on unset parameters or on columns of a higher level query, or sequence values (that means can it be evaluated right now)?static ExpressionVisitorINDEPENDENT_VISITORThe visitor singleton for the type INDEPENDENT.private static ExpressionVisitor[]INDEPENDENT_VISITORSINDEPENDENT listeners with query level 0, 1, ...private long[]maxDataModificationIdstatic intNOT_FROM_RESOLVERDoes an expression have no relation to the given table filter (getResolver)?static intOPTIMIZABLE_AGGREGATEAre all aggregates MIN(column), MAX(column), COUNT(*), MEDIAN(column), ENVELOPE(count) for the given table (getTable)?static intQUERY_COMPARABLECan the expression be added to a condition of an outer query.static ExpressionVisitorQUERY_COMPARABLE_VISITORThe visitor singleton for the type QUERY_COMPARABLE.private intqueryLevelstatic intREADONLYDoes the expression have no side effects (change the data)?static ExpressionVisitorREADONLY_VISITORThe visitor singleton for the type EVALUATABLE.private ColumnResolverresolverprivate java.util.HashSet<?>setstatic intSET_MAX_DATA_MODIFICATION_IDRequest to set the latest modification id (addDataModificationId).private Tabletableprivate inttype
-
Constructor Summary
Constructors Modifier Constructor Description privateExpressionVisitor(int type)privateExpressionVisitor(int type, int queryLevel)privateExpressionVisitor(int type, int queryLevel, java.util.HashSet<?> set, AllColumnsForPlan columns1, Table table, ColumnResolver resolver, long[] maxDataModificationId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddColumn1(Column column)Add a new column to the set of columns.(package private) voidaddColumn2(Column column)Add a new column to the set of columns.voidaddDataModificationId(long value)Update the field maxDataModificationId if this value is higher than the current value.voidaddDependency(DbObject obj)Add a new dependency to the set of dependencies.static voidallColumnsForTableFilters(TableFilter[] filters, AllColumnsForPlan allColumnsSet)Get the set of columns of all tables.java.util.HashSet<ColumnResolver>getColumnResolvers()Get the set of column resolvers.static ExpressionVisitorgetColumnsVisitor(java.util.HashSet<Column> columns, Table table)Create a new visitor to get all referenced columns.static ExpressionVisitorgetColumnsVisitor(AllColumnsForPlan columns)Create a new visitor to get all referenced columns.static ExpressionVisitorgetDecrementQueryLevelVisitor(java.util.HashSet<ColumnResolver> columnResolvers, int queryDecrement)Create a new visitor to decrement query level in columns with the specified resolvers.java.util.HashSet<DbObject>getDependencies()Get the dependency set.static ExpressionVisitorgetDependenciesVisitor(java.util.HashSet<DbObject> dependencies)Create a new visitor object to collect dependencies.longgetMaxDataModificationId()Get the last data modification.static ExpressionVisitorgetMaxModificationIdVisitor()static ExpressionVisitorgetNotFromResolverVisitor(ColumnResolver resolver)Create a new visitor to check if no expression depends on the given resolver.static ExpressionVisitorgetOptimizableVisitor(Table table)Create a new visitor to check if all aggregates are for the given table.(package private) intgetQueryLevel()ColumnResolvergetResolver()Get the column resolver.TablegetTable()Get the table.intgetType()Get the visitor type.ExpressionVisitorincrementQueryLevel(int offset)Increment or decrement the query level.
-
-
-
Field Detail
-
INDEPENDENT
public static final int INDEPENDENT
Is the value independent on unset parameters or on columns of a higher level query, or sequence values (that means can it be evaluated right now)?- See Also:
- Constant Field Values
-
INDEPENDENT_VISITOR
public static final ExpressionVisitor INDEPENDENT_VISITOR
The visitor singleton for the type INDEPENDENT.
-
OPTIMIZABLE_AGGREGATE
public static final int OPTIMIZABLE_AGGREGATE
Are all aggregates MIN(column), MAX(column), COUNT(*), MEDIAN(column), ENVELOPE(count) for the given table (getTable)?- See Also:
- Constant Field Values
-
DETERMINISTIC
public static final int DETERMINISTIC
Does the expression return the same results for the same parameters?- See Also:
- Constant Field Values
-
DETERMINISTIC_VISITOR
public static final ExpressionVisitor DETERMINISTIC_VISITOR
The visitor singleton for the type DETERMINISTIC.
-
EVALUATABLE
public static final int EVALUATABLE
Can the expression be evaluated, that means are all columns set to 'evaluatable'?- See Also:
- Constant Field Values
-
EVALUATABLE_VISITOR
public static final ExpressionVisitor EVALUATABLE_VISITOR
The visitor singleton for the type EVALUATABLE.
-
CACHED
private static final int CACHED
Count of cached INDEPENDENT and EVALUATABLE visitors with different query level.- See Also:
- Constant Field Values
-
INDEPENDENT_VISITORS
private static final ExpressionVisitor[] INDEPENDENT_VISITORS
INDEPENDENT listeners with query level 0, 1, ...
-
EVALUATABLE_VISITORS
private static final ExpressionVisitor[] EVALUATABLE_VISITORS
EVALUATABLE listeners with query level 0, 1, ...
-
SET_MAX_DATA_MODIFICATION_ID
public static final int SET_MAX_DATA_MODIFICATION_ID
Request to set the latest modification id (addDataModificationId).- See Also:
- Constant Field Values
-
READONLY
public static final int READONLY
Does the expression have no side effects (change the data)?- See Also:
- Constant Field Values
-
READONLY_VISITOR
public static final ExpressionVisitor READONLY_VISITOR
The visitor singleton for the type EVALUATABLE.
-
NOT_FROM_RESOLVER
public static final int NOT_FROM_RESOLVER
Does an expression have no relation to the given table filter (getResolver)?- See Also:
- Constant Field Values
-
GET_DEPENDENCIES
public static final int GET_DEPENDENCIES
Request to get the set of dependencies (addDependency).- See Also:
- Constant Field Values
-
QUERY_COMPARABLE
public static final int QUERY_COMPARABLE
Can the expression be added to a condition of an outer query. Example: ROWNUM() can't be added as a condition to the inner query of select id from (select t.*, rownum as r from test t) where r between 2 and 3; Also a sequence expression must not be used.- See Also:
- Constant Field Values
-
GET_COLUMNS1
public static final int GET_COLUMNS1
Get all referenced columns for the optimiser.- See Also:
- Constant Field Values
-
GET_COLUMNS2
public static final int GET_COLUMNS2
Get all referenced columns.- See Also:
- Constant Field Values
-
DECREMENT_QUERY_LEVEL
public static final int DECREMENT_QUERY_LEVEL
Decrement query level of all expression columns.- See Also:
- Constant Field Values
-
QUERY_COMPARABLE_VISITOR
public static final ExpressionVisitor QUERY_COMPARABLE_VISITOR
The visitor singleton for the type QUERY_COMPARABLE.
-
type
private final int type
-
queryLevel
private final int queryLevel
-
set
private final java.util.HashSet<?> set
-
columns1
private final AllColumnsForPlan columns1
-
table
private final Table table
-
maxDataModificationId
private final long[] maxDataModificationId
-
resolver
private final ColumnResolver resolver
-
-
Constructor Detail
-
ExpressionVisitor
private ExpressionVisitor(int type, int queryLevel, java.util.HashSet<?> set, AllColumnsForPlan columns1, Table table, ColumnResolver resolver, long[] maxDataModificationId)
-
ExpressionVisitor
private ExpressionVisitor(int type)
-
ExpressionVisitor
private ExpressionVisitor(int type, int queryLevel)
-
-
Method Detail
-
getDependenciesVisitor
public static ExpressionVisitor getDependenciesVisitor(java.util.HashSet<DbObject> dependencies)
Create a new visitor object to collect dependencies.- Parameters:
dependencies- the dependencies set- Returns:
- the new visitor
-
getOptimizableVisitor
public static ExpressionVisitor getOptimizableVisitor(Table table)
Create a new visitor to check if all aggregates are for the given table.- Parameters:
table- the table- Returns:
- the new visitor
-
getNotFromResolverVisitor
public static ExpressionVisitor getNotFromResolverVisitor(ColumnResolver resolver)
Create a new visitor to check if no expression depends on the given resolver.- Parameters:
resolver- the resolver- Returns:
- the new visitor
-
getColumnsVisitor
public static ExpressionVisitor getColumnsVisitor(AllColumnsForPlan columns)
Create a new visitor to get all referenced columns.- Parameters:
columns- the columns map- Returns:
- the new visitor
-
getColumnsVisitor
public static ExpressionVisitor getColumnsVisitor(java.util.HashSet<Column> columns, Table table)
Create a new visitor to get all referenced columns.- Parameters:
columns- the columns maptable- table to gather columns from, ornullto gather all columns- Returns:
- the new visitor
-
getMaxModificationIdVisitor
public static ExpressionVisitor getMaxModificationIdVisitor()
-
getDecrementQueryLevelVisitor
public static ExpressionVisitor getDecrementQueryLevelVisitor(java.util.HashSet<ColumnResolver> columnResolvers, int queryDecrement)
Create a new visitor to decrement query level in columns with the specified resolvers.- Parameters:
columnResolvers- column resolversqueryDecrement- 0 to check whether operation is allowed, 1 to actually perform the decrement- Returns:
- the new visitor
-
addDependency
public void addDependency(DbObject obj)
Add a new dependency to the set of dependencies. This is used for GET_DEPENDENCIES visitors.- Parameters:
obj- the additional dependency.
-
addColumn1
void addColumn1(Column column)
Add a new column to the set of columns. This is used for GET_COLUMNS visitors.- Parameters:
column- the additional column.
-
addColumn2
void addColumn2(Column column)
Add a new column to the set of columns. This is used for GET_COLUMNS2 visitors.- Parameters:
column- the additional column.
-
getDependencies
public java.util.HashSet<DbObject> getDependencies()
Get the dependency set. This is used for GET_DEPENDENCIES visitors.- Returns:
- the set
-
incrementQueryLevel
public ExpressionVisitor incrementQueryLevel(int offset)
Increment or decrement the query level.- Parameters:
offset- 1 to increment, -1 to decrement- Returns:
- this visitor or its clone with the changed query level
-
getResolver
public ColumnResolver getResolver()
Get the column resolver. This is used for NOT_FROM_RESOLVER visitors.- Returns:
- the column resolver
-
getColumnResolvers
public java.util.HashSet<ColumnResolver> getColumnResolvers()
Get the set of column resolvers. This is used forDECREMENT_QUERY_LEVELvisitors.- Returns:
- the set
-
addDataModificationId
public void addDataModificationId(long value)
Update the field maxDataModificationId if this value is higher than the current value. This is used for SET_MAX_DATA_MODIFICATION_ID visitors.- Parameters:
value- the data modification id
-
getMaxDataModificationId
public long getMaxDataModificationId()
Get the last data modification. This is used for SET_MAX_DATA_MODIFICATION_ID visitors.- Returns:
- the maximum modification id
-
getQueryLevel
int getQueryLevel()
-
getTable
public Table getTable()
Get the table. This is used for OPTIMIZABLE_MIN_MAX_COUNT_ALL visitors.- Returns:
- the table
-
getType
public int getType()
Get the visitor type.- Returns:
- the type
-
allColumnsForTableFilters
public static void allColumnsForTableFilters(TableFilter[] filters, AllColumnsForPlan allColumnsSet)
Get the set of columns of all tables.- Parameters:
filters- the filtersallColumnsSet- the on-demand all-columns set
-
-