Package org.h2.expression
Class ExpressionVisitor
java.lang.Object
org.h2.expression.ExpressionVisitor
The visitor pattern is used to iterate through all expressions of a query
to optimize a statement.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDecrement query level of all expression columns.static final intDoes the expression return the same results for the same parameters?static final ExpressionVisitorThe visitor singleton for the type DETERMINISTIC.static final intCan the expression be evaluated, that means are all columns set to 'evaluatable'?static final ExpressionVisitorThe visitor singleton for the type EVALUATABLE.static final intGet all referenced columns for the optimiser.static final intGet all referenced columns.static final intRequest to get the set of dependencies (addDependency).static final intIs 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 final ExpressionVisitorThe visitor singleton for the type INDEPENDENT.static final intDoes an expression have no relation to the given table filter (getResolver)?static final intAre all aggregates MIN(column), MAX(column), COUNT(*), MEDIAN(column), ENVELOPE(count) for the given table (getTable)?static final intCan the expression be added to a condition of an outer query.static final ExpressionVisitorThe visitor singleton for the type QUERY_COMPARABLE.static final intDoes the expression have no side effects (change the data)?static final ExpressionVisitorThe visitor singleton for the type EVALUATABLE.static final intRequest to set the latest modification id (addDataModificationId). -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDataModificationId(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.Get the set of column resolvers.static ExpressionVisitorgetColumnsVisitor(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(HashSet<ColumnResolver> columnResolvers, int queryDecrement) Create a new visitor to decrement query level in columns with the specified resolvers.Get the dependency set.static ExpressionVisitorgetDependenciesVisitor(HashSet<DbObject> dependencies) Create a new visitor object to collect dependencies.longGet the last data modification.static ExpressionVisitorstatic 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.Get the column resolver.getTable()Get the table.intgetType()Get the visitor type.incrementQueryLevel(int offset) Increment or decrement the query level.
-
Field Details
-
INDEPENDENT
public static final int INDEPENDENTIs 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:
-
INDEPENDENT_VISITOR
The visitor singleton for the type INDEPENDENT. -
OPTIMIZABLE_AGGREGATE
public static final int OPTIMIZABLE_AGGREGATEAre all aggregates MIN(column), MAX(column), COUNT(*), MEDIAN(column), ENVELOPE(count) for the given table (getTable)?- See Also:
-
DETERMINISTIC
public static final int DETERMINISTICDoes the expression return the same results for the same parameters?- See Also:
-
DETERMINISTIC_VISITOR
The visitor singleton for the type DETERMINISTIC. -
EVALUATABLE
public static final int EVALUATABLECan the expression be evaluated, that means are all columns set to 'evaluatable'?- See Also:
-
EVALUATABLE_VISITOR
The visitor singleton for the type EVALUATABLE. -
SET_MAX_DATA_MODIFICATION_ID
public static final int SET_MAX_DATA_MODIFICATION_IDRequest to set the latest modification id (addDataModificationId).- See Also:
-
READONLY
public static final int READONLYDoes the expression have no side effects (change the data)?- See Also:
-
READONLY_VISITOR
The visitor singleton for the type EVALUATABLE. -
NOT_FROM_RESOLVER
public static final int NOT_FROM_RESOLVERDoes an expression have no relation to the given table filter (getResolver)?- See Also:
-
GET_DEPENDENCIES
public static final int GET_DEPENDENCIESRequest to get the set of dependencies (addDependency).- See Also:
-
QUERY_COMPARABLE
public static final int QUERY_COMPARABLECan 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:
-
GET_COLUMNS1
public static final int GET_COLUMNS1Get all referenced columns for the optimiser.- See Also:
-
GET_COLUMNS2
public static final int GET_COLUMNS2Get all referenced columns.- See Also:
-
DECREMENT_QUERY_LEVEL
public static final int DECREMENT_QUERY_LEVELDecrement query level of all expression columns.- See Also:
-
QUERY_COMPARABLE_VISITOR
The visitor singleton for the type QUERY_COMPARABLE.
-
-
Method Details
-
getDependenciesVisitor
Create a new visitor object to collect dependencies.- Parameters:
dependencies- the dependencies set- Returns:
- the new visitor
-
getOptimizableVisitor
Create a new visitor to check if all aggregates are for the given table.- Parameters:
table- the table- Returns:
- the new visitor
-
getNotFromResolverVisitor
Create a new visitor to check if no expression depends on the given resolver.- Parameters:
resolver- the resolver- Returns:
- the new visitor
-
getColumnsVisitor
Create a new visitor to get all referenced columns.- Parameters:
columns- the columns map- Returns:
- the new visitor
-
getColumnsVisitor
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
-
getDecrementQueryLevelVisitor
public static ExpressionVisitor getDecrementQueryLevelVisitor(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
Add a new dependency to the set of dependencies. This is used for GET_DEPENDENCIES visitors.- Parameters:
obj- the additional dependency.
-
getDependencies
Get the dependency set. This is used for GET_DEPENDENCIES visitors.- Returns:
- the set
-
incrementQueryLevel
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
Get the column resolver. This is used for NOT_FROM_RESOLVER visitors.- Returns:
- the column resolver
-
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
-
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
-