org.h2.table
Class TableFilter

java.lang.Object
  extended by org.h2.table.TableFilter
All Implemented Interfaces:
ColumnResolver

public class TableFilter
extends java.lang.Object
implements ColumnResolver

A table filter represents a table that is used in a query. There is one such object whenever a table (or view) is used in a query. For example the following query has 2 table filters: SELECT * FROM TEST T1, TEST T2.


Constructor Summary
TableFilter(Session session, Table table, java.lang.String alias, boolean rightsChecked, Select select)
          Create a new table filter object.
 
Method Summary
 void addFilterCondition(Expression condition, boolean join)
          Add a filter condition.
 void addIndexCondition(IndexCondition condition)
          Add an index condition.
 void addJoin(TableFilter filter, boolean outer, Expression on)
          Add a joined table.
 void addNaturalJoinColumn(Column c)
          Add a column to the natural join key column list.
 Row get()
          Get the current row.
 PlanItem getBestPlanItem(Session session, int level)
          Get the best plan item (index, cost) to use use for the current join order.
 Column[] getColumns()
          Get the column list.
 Expression getFilterCondition()
           
 Index getIndex()
           
 TableFilter getJoin()
           
 Expression getJoinCondition()
           
 java.lang.String getPlanSQL(boolean join)
          Get the query execution plan text to use for this table filter.
 java.lang.String getSchemaName()
          Get the schema name.
 Select getSelect()
          Get the select statement.
 Column[] getSystemColumns()
          Get the system columns that this table understands.
 Table getTable()
           
 java.lang.String getTableAlias()
          Get the table alias name.
 TableFilter getTableFilter()
          Get the table filter.
 Value getValue(Column column)
          Get the value for the given column.
 int hashCode()
           
 boolean hasInComparisons()
          Are there any index conditions that involve IN(...).
 boolean isJoinOuter()
          Check if this is an outer joined table.
 boolean isNaturalJoinColumn(Column c)
          Check if the given column is a natural join column.
 boolean isUsed()
           
 void lock(Session session, boolean exclusive, boolean force)
          Lock the table.
 void mapAndAddFilter(Expression on)
          Map the columns and add the join condition.
 boolean next()
          Check if there are more rows to read.
 Expression optimize(ExpressionColumn expressionColumn, Column column)
          Get the expression that represents this column.
 void prepare()
          Prepare reading rows.
 void removeFilterCondition()
          Remove the filter condition.
 void removeJoin()
          Remove the joined table
 void removeJoinCondition()
          Remove the join condition.
 void reset()
          Reset to the current position.
 void set(Row current)
          Set the current row.
 void setAlias(java.lang.String alias)
           
 void setEvaluatable(TableFilter filter, boolean b)
          Update the filter and join conditions of this and all joined tables with the information that the given table filter can now return rows or not.
 void setFullCondition(Expression condition)
           
 void setIndex(Index index)
           
 void setPlanItem(PlanItem item)
          Set what plan item (index, cost) to use use.
 void setUsed(boolean used)
           
 void startQuery(Session session)
          Start the query.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableFilter

public TableFilter(Session session,
                   Table table,
                   java.lang.String alias,
                   boolean rightsChecked,
                   Select select)
            throws java.sql.SQLException
Create a new table filter object.

Parameters:
session - the session
table - the table from where to read data
alias - the alias name
rightsChecked - true if rights are already checked
select - the select statement
Throws:
java.sql.SQLException
Method Detail

getSelect

public Select getSelect()
Description copied from interface: ColumnResolver
Get the select statement.

Specified by:
getSelect in interface ColumnResolver
Returns:
the select statement

getTable

public Table getTable()

lock

public void lock(Session session,
                 boolean exclusive,
                 boolean force)
          throws java.sql.SQLException
Lock the table. This will also lock joined tables.

Parameters:
session - the session
exclusive - true if an exclusive lock is required
force - lock even in the MVCC mode
Throws:
java.sql.SQLException

getBestPlanItem

public PlanItem getBestPlanItem(Session session,
                                int level)
                         throws java.sql.SQLException
Get the best plan item (index, cost) to use use for the current join order.

Parameters:
session - the session
level - 1 for the first table in a join, 2 for the second, and so on
Returns:
the best plan item
Throws:
java.sql.SQLException

setPlanItem

public void setPlanItem(PlanItem item)
Set what plan item (index, cost) to use use.

Parameters:
item - the plan item

prepare

public void prepare()
             throws java.sql.SQLException
Prepare reading rows. This method will remove all index conditions that can not be used, and optimize the conditions.

Throws:
java.sql.SQLException

startQuery

public void startQuery(Session session)
Start the query. This will reset the scan counts.

Parameters:
session - the session

reset

public void reset()
Reset to the current position.


next

public boolean next()
             throws java.sql.SQLException
Check if there are more rows to read.

Returns:
true if there are
Throws:
java.sql.SQLException

get

public Row get()
        throws java.sql.SQLException
Get the current row.

Returns:
the current row, or null
Throws:
java.sql.SQLException

set

public void set(Row current)
Set the current row.

Parameters:
current - the current row

getTableAlias

public java.lang.String getTableAlias()
Get the table alias name. If no alias is specified, the table name is returned.

Specified by:
getTableAlias in interface ColumnResolver
Returns:
the alias name

addIndexCondition

public void addIndexCondition(IndexCondition condition)
Add an index condition.

Parameters:
condition - the index condition

addFilterCondition

public void addFilterCondition(Expression condition,
                               boolean join)
Add a filter condition.

Parameters:
condition - the condition
join - if this is in fact a join condition

addJoin

public void addJoin(TableFilter filter,
                    boolean outer,
                    Expression on)
             throws java.sql.SQLException
Add a joined table.

Parameters:
filter - the joined table filter
outer - if this is an outer join
on - the join condition
Throws:
java.sql.SQLException

mapAndAddFilter

public void mapAndAddFilter(Expression on)
                     throws java.sql.SQLException
Map the columns and add the join condition.

Parameters:
on - the condition
Throws:
java.sql.SQLException

getJoin

public TableFilter getJoin()

isJoinOuter

public boolean isJoinOuter()
Check if this is an outer joined table.

Returns:
true if it is

getPlanSQL

public java.lang.String getPlanSQL(boolean join)
Get the query execution plan text to use for this table filter.

Parameters:
join - if this is a joined table
Returns:
the SQL statement snippet

getIndex

public Index getIndex()

setIndex

public void setIndex(Index index)

setUsed

public void setUsed(boolean used)

isUsed

public boolean isUsed()

removeJoin

public void removeJoin()
Remove the joined table


getJoinCondition

public Expression getJoinCondition()

removeJoinCondition

public void removeJoinCondition()
Remove the join condition.


getFilterCondition

public Expression getFilterCondition()

removeFilterCondition

public void removeFilterCondition()
Remove the filter condition.


setFullCondition

public void setFullCondition(Expression condition)

setEvaluatable

public void setEvaluatable(TableFilter filter,
                           boolean b)
Update the filter and join conditions of this and all joined tables with the information that the given table filter can now return rows or not.

Parameters:
filter - the table filter
b - the new flag

getSchemaName

public java.lang.String getSchemaName()
Description copied from interface: ColumnResolver
Get the schema name.

Specified by:
getSchemaName in interface ColumnResolver
Returns:
the schema name

getColumns

public Column[] getColumns()
Description copied from interface: ColumnResolver
Get the column list.

Specified by:
getColumns in interface ColumnResolver
Returns:
the column list

getSystemColumns

public Column[] getSystemColumns()
Get the system columns that this table understands. This is used for compatibility with other databases. The columns are only returned if the current mode supports system columns.

Specified by:
getSystemColumns in interface ColumnResolver
Returns:
the system columns

getValue

public Value getValue(Column column)
               throws java.sql.SQLException
Description copied from interface: ColumnResolver
Get the value for the given column.

Specified by:
getValue in interface ColumnResolver
Parameters:
column - the column
Returns:
the value
Throws:
java.sql.SQLException

getTableFilter

public TableFilter getTableFilter()
Description copied from interface: ColumnResolver
Get the table filter.

Specified by:
getTableFilter in interface ColumnResolver
Returns:
the table filter

setAlias

public void setAlias(java.lang.String alias)

optimize

public Expression optimize(ExpressionColumn expressionColumn,
                           Column column)
Description copied from interface: ColumnResolver
Get the expression that represents this column.

Specified by:
optimize in interface ColumnResolver
Parameters:
expressionColumn - the expression column
column - the column
Returns:
the optimized expression

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addNaturalJoinColumn

public void addNaturalJoinColumn(Column c)
Add a column to the natural join key column list.

Parameters:
c - the column to add

isNaturalJoinColumn

public boolean isNaturalJoinColumn(Column c)
Check if the given column is a natural join column.

Parameters:
c - the column to check
Returns:
true if this is a joined natural join column

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

hasInComparisons

public boolean hasInComparisons()
Are there any index conditions that involve IN(...).

Returns:
whether there are IN(...) comparisons