Top Description Fields Constructors Methods
org.h2.expression

public final Class ExpressionVisitor

extends Object
Class Inheritance
Imports
java.util.HashSet, org.h2.command.query.AllColumnsForPlan, org.h2.engine.DbObject, org.h2.table.Column, .ColumnResolver, .Table, .TableFilter

The visitor pattern is used to iterate through all expressions of a query to optimize a statement.

Field Summary

Modifier and TypeField and Description
private static final int
CACHED

Count of cached INDEPENDENT and EVALUATABLE visitors with different query level.

private final AllColumnsForPlan
public static final int
DECREMENT_QUERY_LEVEL

Decrement query level of all expression columns.

public static final int
DETERMINISTIC

Does the expression return the same results for the same parameters?

public static final ExpressionVisitor
DETERMINISTIC_VISITOR

The visitor singleton for the type DETERMINISTIC.

public static final int
EVALUATABLE

Can the expression be evaluated, that means are all columns set to 'evaluatable'?

public static final ExpressionVisitor
EVALUATABLE_VISITOR

The visitor singleton for the type EVALUATABLE.

private static final ExpressionVisitor[]
EVALUATABLE_VISITORS

EVALUATABLE listeners with query level 0, 1, ...

public static final int
GET_COLUMNS1

Get all referenced columns for the optimiser.

public static final int
GET_COLUMNS2

Get all referenced columns.

public static final int
GET_DEPENDENCIES

Request to get the set of dependencies (addDependency).

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)?

public static final ExpressionVisitor
INDEPENDENT_VISITOR

The visitor singleton for the type INDEPENDENT.

private static final ExpressionVisitor[]
INDEPENDENT_VISITORS

INDEPENDENT listeners with query level 0, 1, ...

private final long[]
public static final int
NOT_FROM_RESOLVER

Does an expression have no relation to the given table filter (getResolver)?

public static final int
OPTIMIZABLE_AGGREGATE

Are all aggregates MIN(column), MAX(column), COUNT(*), MEDIAN(column), ENVELOPE(count) for the given table (getTable)?

public static final int
QUERY_COMPARABLE

Can the expression be added to a condition of an outer query.

public static final ExpressionVisitor
QUERY_COMPARABLE_VISITOR

The visitor singleton for the type QUERY_COMPARABLE.

private final int
public static final int
READONLY

Does the expression have no side effects (change the data)?

public static final ExpressionVisitor
READONLY_VISITOR

The visitor singleton for the type EVALUATABLE.

private final ColumnResolver
private final HashSet<?>
public static final int
SET_MAX_DATA_MODIFICATION_ID

Request to set the latest modification id (addDataModificationId).

private final Table
private final int

Constructor Summary

AccessConstructor and Description
private
ExpressionVisitor(int type, int queryLevel, HashSet<?> set, AllColumnsForPlan columns1, Table table, ColumnResolver resolver, long[] maxDataModificationId)

private
private
ExpressionVisitor(int type, int queryLevel)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addColumn1(Column
the additional column.
column
)

Add a new column to the set of columns.

pack-priv void
addColumn2(Column
the additional column.
column
)

Add a new column to the set of columns.

public void
addDataModificationId(long
the data modification id
value
)

Update the field maxDataModificationId if this value is higher than the current value.

public void
addDependency(DbObject
the additional dependency.
obj
)

Add a new dependency to the set of dependencies.

public static void
allColumnsForTableFilters(TableFilter[]
the filters
filters
,
AllColumnsForPlan
the on-demand all-columns set
allColumnsSet
)

Get the set of columns of all tables.

public HashSet<ColumnResolver>

Returns:

the set
getColumnResolvers
()

Get the set of column resolvers.

public static ExpressionVisitor

Returns:

the new visitor
getColumnsVisitor
(AllColumnsForPlan
the columns map
columns
)

Create a new visitor to get all referenced columns.

public static ExpressionVisitor

Returns:

the new visitor
getColumnsVisitor
(HashSet<Column>
the columns map
columns
,
Table
table to gather columns from, or null to gather all columns
table
)

Create a new visitor to get all referenced columns.

public static ExpressionVisitor

Returns:

the new visitor
getDecrementQueryLevelVisitor
(HashSet<ColumnResolver>
column resolvers
columnResolvers
,
int
0 to check whether operation is allowed, 1 to actually perform the decrement
queryDecrement
)

Create a new visitor to decrement query level in columns with the specified resolvers.

public HashSet<DbObject>

Returns:

the set
getDependencies
()

Get the dependency set.

public static ExpressionVisitor

Returns:

the new visitor
getDependenciesVisitor
(HashSet<DbObject>
the dependencies set
dependencies
)

Create a new visitor object to collect dependencies.

public long

Returns:

the maximum modification id
getMaxDataModificationId
()

Get the last data modification.

public static ExpressionVisitor
public static ExpressionVisitor

Returns:

the new visitor
getNotFromResolverVisitor
(ColumnResolver
the resolver
resolver
)

Create a new visitor to check if no expression depends on the given resolver.

public static ExpressionVisitor

Returns:

the new visitor
getOptimizableVisitor
(Table
the table
table
)

Create a new visitor to check if all aggregates are for the given table.

pack-priv int
public ColumnResolver

Returns:

the column resolver
getResolver
()

Get the column resolver.

public Table

Returns:

the table
getTable
()

Get the table.

public int

Returns:

the type
getType
()

Get the visitor type.

public ExpressionVisitor

Returns:

this visitor or its clone with the changed query level
incrementQueryLevel
(int
1 to increment, -1 to decrement
offset
)

Increment or decrement the query level.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CACHEDback to summary
private static final int CACHED

Count of cached INDEPENDENT and EVALUATABLE visitors with different query level.

columns1back to summary
private final AllColumnsForPlan columns1
DECREMENT_QUERY_LEVELback to summary
public static final int DECREMENT_QUERY_LEVEL

Decrement query level of all expression columns.

DETERMINISTICback to summary
public static final int DETERMINISTIC

Does the expression return the same results for the same parameters?

DETERMINISTIC_VISITORback to summary
public static final ExpressionVisitor DETERMINISTIC_VISITOR

The visitor singleton for the type DETERMINISTIC.

EVALUATABLEback to summary
public static final int EVALUATABLE

Can the expression be evaluated, that means are all columns set to 'evaluatable'?

EVALUATABLE_VISITORback to summary
public static final ExpressionVisitor EVALUATABLE_VISITOR

The visitor singleton for the type EVALUATABLE.

EVALUATABLE_VISITORSback to summary
private static final ExpressionVisitor[] EVALUATABLE_VISITORS

EVALUATABLE listeners with query level 0, 1, ...

GET_COLUMNS1back to summary
public static final int GET_COLUMNS1

Get all referenced columns for the optimiser.

GET_COLUMNS2back to summary
public static final int GET_COLUMNS2

Get all referenced columns.

GET_DEPENDENCIESback to summary
public static final int GET_DEPENDENCIES

Request to get the set of dependencies (addDependency).

INDEPENDENTback to summary
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)?

INDEPENDENT_VISITORback to summary
public static final ExpressionVisitor INDEPENDENT_VISITOR

The visitor singleton for the type INDEPENDENT.

INDEPENDENT_VISITORSback to summary
private static final ExpressionVisitor[] INDEPENDENT_VISITORS

INDEPENDENT listeners with query level 0, 1, ...

maxDataModificationIdback to summary
private final long[] maxDataModificationId
NOT_FROM_RESOLVERback to summary
public static final int NOT_FROM_RESOLVER

Does an expression have no relation to the given table filter (getResolver)?

OPTIMIZABLE_AGGREGATEback to summary
public static final int OPTIMIZABLE_AGGREGATE

Are all aggregates MIN(column), MAX(column), COUNT(*), MEDIAN(column), ENVELOPE(count) for the given table (getTable)?

QUERY_COMPARABLEback to summary
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.

QUERY_COMPARABLE_VISITORback to summary
public static final ExpressionVisitor QUERY_COMPARABLE_VISITOR

The visitor singleton for the type QUERY_COMPARABLE.

queryLevelback to summary
private final int queryLevel
READONLYback to summary
public static final int READONLY

Does the expression have no side effects (change the data)?

READONLY_VISITORback to summary
public static final ExpressionVisitor READONLY_VISITOR

The visitor singleton for the type EVALUATABLE.

resolverback to summary
private final ColumnResolver resolver
setback to summary
private final HashSet<?> set
SET_MAX_DATA_MODIFICATION_IDback to summary
public static final int SET_MAX_DATA_MODIFICATION_ID

Request to set the latest modification id (addDataModificationId).

tableback to summary
private final Table table
typeback to summary
private final int type

Constructor Detail

ExpressionVisitorback to summary
private ExpressionVisitor(int type, int queryLevel, HashSet<?> set, AllColumnsForPlan columns1, Table table, ColumnResolver resolver, long[] maxDataModificationId)
ExpressionVisitorback to summary
private ExpressionVisitor(int type)
ExpressionVisitorback to summary
private ExpressionVisitor(int type, int queryLevel)

Method Detail

addColumn1back to summary
pack-priv void addColumn1(Column column)

Add a new column to the set of columns. This is used for GET_COLUMNS visitors.

Parameters
column:Column

the additional column.

addColumn2back to summary
pack-priv void addColumn2(Column column)

Add a new column to the set of columns. This is used for GET_COLUMNS2 visitors.

Parameters
column:Column

the additional column.

Annotations
@SuppressWarnings:unchecked
addDataModificationIdback to summary
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:long

the data modification id

addDependencyback to summary
public void addDependency(DbObject obj)

Add a new dependency to the set of dependencies. This is used for GET_DEPENDENCIES visitors.

Parameters
obj:DbObject

the additional dependency.

Annotations
@SuppressWarnings:unchecked
allColumnsForTableFiltersback to summary
public static void allColumnsForTableFilters(TableFilter[] filters, AllColumnsForPlan allColumnsSet)

Get the set of columns of all tables.

Parameters
filters:TableFilter[]

the filters

allColumnsSet:AllColumnsForPlan

the on-demand all-columns set

getColumnResolversback to summary
public HashSet<ColumnResolver> getColumnResolvers()

Get the set of column resolvers. This is used for DECREMENT_QUERY_LEVEL visitors.

Returns:HashSet<ColumnResolver>

the set

Annotations
@SuppressWarnings:unchecked
getColumnsVisitorback to summary
public static ExpressionVisitor getColumnsVisitor(AllColumnsForPlan columns)

Create a new visitor to get all referenced columns.

Parameters
columns:AllColumnsForPlan

the columns map

Returns:ExpressionVisitor

the new visitor

getColumnsVisitorback to summary
public static ExpressionVisitor getColumnsVisitor(HashSet<Column> columns, Table table)

Create a new visitor to get all referenced columns.

Parameters
columns:HashSet<Column>

the columns map

table:Table

table to gather columns from, or null to gather all columns

Returns:ExpressionVisitor

the new visitor

getDecrementQueryLevelVisitorback to summary
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:HashSet<ColumnResolver>

column resolvers

queryDecrement:int

0 to check whether operation is allowed, 1 to actually perform the decrement

Returns:ExpressionVisitor

the new visitor

getDependenciesback to summary
public HashSet<DbObject> getDependencies()

Get the dependency set. This is used for GET_DEPENDENCIES visitors.

Returns:HashSet<DbObject>

the set

Annotations
@SuppressWarnings:unchecked
getDependenciesVisitorback to summary
public static ExpressionVisitor getDependenciesVisitor(HashSet<DbObject> dependencies)

Create a new visitor object to collect dependencies.

Parameters
dependencies:HashSet<DbObject>

the dependencies set

Returns:ExpressionVisitor

the new visitor

getMaxDataModificationIdback to summary
public long getMaxDataModificationId()

Get the last data modification. This is used for SET_MAX_DATA_MODIFICATION_ID visitors.

Returns:long

the maximum modification id

getMaxModificationIdVisitorback to summary
public static ExpressionVisitor getMaxModificationIdVisitor()
getNotFromResolverVisitorback to summary
public static ExpressionVisitor getNotFromResolverVisitor(ColumnResolver resolver)

Create a new visitor to check if no expression depends on the given resolver.

Parameters
resolver:ColumnResolver

the resolver

Returns:ExpressionVisitor

the new visitor

getOptimizableVisitorback to summary
public static ExpressionVisitor getOptimizableVisitor(Table table)

Create a new visitor to check if all aggregates are for the given table.

Parameters
table:Table

the table

Returns:ExpressionVisitor

the new visitor

getQueryLevelback to summary
pack-priv int getQueryLevel()
getResolverback to summary
public ColumnResolver getResolver()

Get the column resolver. This is used for NOT_FROM_RESOLVER visitors.

Returns:ColumnResolver

the column resolver

getTableback to summary
public Table getTable()

Get the table. This is used for OPTIMIZABLE_MIN_MAX_COUNT_ALL visitors.

Returns:Table

the table

getTypeback to summary
public int getType()

Get the visitor type.

Returns:int

the type

incrementQueryLevelback to summary
public ExpressionVisitor incrementQueryLevel(int offset)

Increment or decrement the query level.

Parameters
offset:int

1 to increment, -1 to decrement

Returns:ExpressionVisitor

this visitor or its clone with the changed query level