Class ExpressionVisitor

java.lang.Object
org.h2.expression.ExpressionVisitor

public final class ExpressionVisitor extends Object
The visitor pattern is used to iterate through all expressions of a query to optimize a statement.
  • Field Details

    • 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:
    • 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:
    • DETERMINISTIC

      public static final int DETERMINISTIC
      Does the expression return the same results for the same parameters?
      See Also:
    • 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:
    • 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:
    • 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:
    • READONLY

      public static final int READONLY
      Does the expression have no side effects (change the data)?
      See Also:
    • 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:
    • GET_DEPENDENCIES

      public static final int GET_DEPENDENCIES
      Request to get the set of dependencies (addDependency).
      See Also:
    • 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:
    • GET_COLUMNS1

      public static final int GET_COLUMNS1
      Get all referenced columns for the optimiser.
      See Also:
    • GET_COLUMNS2

      public static final int GET_COLUMNS2
      Get all referenced columns.
      See Also:
    • DECREMENT_QUERY_LEVEL

      public static final int DECREMENT_QUERY_LEVEL
      Decrement query level of all expression columns.
      See Also:
    • 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 HashSet<?> set
    • columns1

      private final AllColumnsForPlan columns1
    • table

      private final Table table
    • maxDataModificationId

      private final long[] maxDataModificationId
    • resolver

      private final ColumnResolver 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

      public static ExpressionVisitor getDependenciesVisitor(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(HashSet<Column> columns, Table table)
      Create a new visitor to get all referenced columns.
      Parameters:
      columns - the columns map
      table - table to gather columns from, or null to gather all columns
      Returns:
      the new visitor
    • getMaxModificationIdVisitor

      public static ExpressionVisitor 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 resolvers
      queryDecrement - 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 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 HashSet<ColumnResolver> getColumnResolvers()
      Get the set of column resolvers. This is used for DECREMENT_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

      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 filters
      allColumnsSet - the on-demand all-columns set