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 TypeFieldDescriptionprivate static final int
Count of cached INDEPENDENT and EVALUATABLE visitors with different query level.private final AllColumnsForPlan
static final int
Decrement query level of all expression columns.static final int
Does the expression return the same results for the same parameters?static final ExpressionVisitor
The visitor singleton for the type DETERMINISTIC.static final int
Can the expression be evaluated, that means are all columns set to 'evaluatable'?static final ExpressionVisitor
The visitor singleton for the type EVALUATABLE.private static final ExpressionVisitor[]
EVALUATABLE listeners with query level 0, 1, ...static final int
Get all referenced columns for the optimiser.static final int
Get all referenced columns.static final int
Request to get the set of dependencies (addDependency).static final int
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)?static final ExpressionVisitor
The visitor singleton for the type INDEPENDENT.private static final ExpressionVisitor[]
INDEPENDENT listeners with query level 0, 1, ...private final long[]
static final int
Does an expression have no relation to the given table filter (getResolver)?static final int
Are all aggregates MIN(column), MAX(column), COUNT(*), MEDIAN(column), ENVELOPE(count) for the given table (getTable)?static final int
Can the expression be added to a condition of an outer query.static final ExpressionVisitor
The visitor singleton for the type QUERY_COMPARABLE.private final int
static final int
Does the expression have no side effects (change the data)?static final ExpressionVisitor
The visitor singleton for the type EVALUATABLE.private final ColumnResolver
private final HashSet
<?> static final int
Request to set the latest modification id (addDataModificationId).private final Table
private final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ExpressionVisitor
(int type) private
ExpressionVisitor
(int type, int queryLevel) private
ExpressionVisitor
(int type, int queryLevel, HashSet<?> set, AllColumnsForPlan columns1, Table table, ColumnResolver resolver, long[] maxDataModificationId) -
Method Summary
Modifier and TypeMethodDescription(package private) void
addColumn1
(Column column) Add a new column to the set of columns.(package private) void
addColumn2
(Column column) Add a new column to the set of columns.void
addDataModificationId
(long value) Update the field maxDataModificationId if this value is higher than the current value.void
addDependency
(DbObject obj) Add a new dependency to the set of dependencies.static void
allColumnsForTableFilters
(TableFilter[] filters, AllColumnsForPlan allColumnsSet) Get the set of columns of all tables.Get the set of column resolvers.static ExpressionVisitor
getColumnsVisitor
(HashSet<Column> columns, Table table) Create a new visitor to get all referenced columns.static ExpressionVisitor
getColumnsVisitor
(AllColumnsForPlan columns) Create a new visitor to get all referenced columns.static ExpressionVisitor
getDecrementQueryLevelVisitor
(HashSet<ColumnResolver> columnResolvers, int queryDecrement) Create a new visitor to decrement query level in columns with the specified resolvers.Get the dependency set.static ExpressionVisitor
getDependenciesVisitor
(HashSet<DbObject> dependencies) Create a new visitor object to collect dependencies.long
Get the last data modification.static ExpressionVisitor
static ExpressionVisitor
getNotFromResolverVisitor
(ColumnResolver resolver) Create a new visitor to check if no expression depends on the given resolver.static ExpressionVisitor
getOptimizableVisitor
(Table table) Create a new visitor to check if all aggregates are for the given table.(package private) int
Get the column resolver.getTable()
Get the table.int
getType()
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. -
CACHED
private static final int CACHEDCount of cached INDEPENDENT and EVALUATABLE visitors with different query level.- See Also:
-
INDEPENDENT_VISITORS
INDEPENDENT listeners with query level 0, 1, ... -
EVALUATABLE_VISITORS
EVALUATABLE listeners with query level 0, 1, ... -
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. -
type
private final int type -
queryLevel
private final int queryLevel -
set
-
columns1
-
table
-
maxDataModificationId
private final long[] maxDataModificationId -
resolver
-
-
Constructor Details
-
ExpressionVisitor
private ExpressionVisitor(int type, int queryLevel, HashSet<?> set, AllColumnsForPlan columns1, Table table, ColumnResolver resolver, long[] maxDataModificationId) -
ExpressionVisitor
private ExpressionVisitor(int type) -
ExpressionVisitor
private ExpressionVisitor(int type, int queryLevel)
-
-
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, ornull
to 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.
-
addColumn1
Add a new column to the set of columns. This is used for GET_COLUMNS visitors.- Parameters:
column
- the additional column.
-
addColumn2
Add a new column to the set of columns. This is used for GET_COLUMNS2 visitors.- Parameters:
column
- the additional column.
-
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_LEVEL
visitors.- 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
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
-