Package org.h2.table
Class TableFilter
java.lang.Object
org.h2.table.TableFilter
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA visitor for table filters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether this is a direct or indirect (nested) outer joinstatic final Comparator<TableFilter>Comparator that uses order in FROM clause as a sort key. -
Constructor Summary
ConstructorsConstructorDescriptionTableFilter(SessionLocal session, Table table, String alias, boolean rightsChecked, Select select, int orderInFrom, IndexHints indexHints) Create a new table filter object. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommonJoinColumns(Column leftColumn, Column replacementColumn, TableFilter replacementFilter) Add a column to the common join column list for a left table filter.voidaddCommonJoinColumnToExclude(Column columnToExclude) Add an excluded column to the common join column list.voidaddFilterCondition(Expression condition, boolean isJoin) Add a filter condition.voidaddIndexCondition(IndexCondition condition) Add an index condition.voidaddJoin(TableFilter filter, boolean outer, Expression on) Add a joined table.voidCreate the index conditions for this filter if needed.findColumn(String name) Get the column with the specified name.get()Get the current row.getBestPlanItem(SessionLocal s, TableFilter[] filters, int filter, AllColumnsForPlan allColumnsSet) Get the best plan item (index, cost) to use for the current join order.Get the column with the given name.getColumnName(Column column) Get the name of the specified column.Column[]Get the column list.Returns common join columns map.Returns common join columns table filter.getIndex()getJoin()int[]getMasks()intGet the order number (index) of this table filter in the "from" clause of the query.getPlanSQL(StringBuilder builder, boolean isJoin, int sqlFlags) Get the query execution plan text to use for this table filter and append it to the specified builder.Get the row id pseudo column, if there is one.Get the schema name or null.Get the select statement.Column[]Get the system columns that this table understands.getTable()Get the table alias name.Get the table filter.Get the value for the given column.booleanReturns whether this column resolver has a derived column list.inthashCode()booleanAre there any index conditions that involve IN(...).booleanCheck if the given column is an excluded common join column.booleanbooleanWhether this is an outer joined table.booleanWhether this is indirectly an outer joined table (nested within an inner join).booleanReturns whether this is a table filter with implicit DUAL table for a SELECT without a FROM clause.booleanbooleanisUsed()voidlock(SessionLocal s) Lock the table.voidMap the columns and add the join condition.booleannext()Check if there are more rows to read.voidprepare()Prepare reading rows.voidRemove the filter condition.voidRemove the joined tablevoidRemove the join condition.voidreset()Reset to the current position.voidSet the current row.voidvoidsetDerivedColumns(ArrayList<String> derivedColumnNames) Set derived column list.voidsetEvaluatable(boolean evaluatable) voidsetEvaluatable(TableFilter filter, boolean b) Update the filter and join conditions of this and all joined tables with the information that the given table filter and all nested filter can now return rows or not.voidsetFullCondition(Expression condition) voidvoidsetNestedJoin(TableFilter filter) Set a nested joined table.protected voidSet the state of this and all nested tables to the NULL row.voidsetPlanItem(PlanItem item) Set what plan item (index, cost, masks) to use.voidsetUsed(boolean used) voidStart the query.toString()voidvisit(TableFilter.TableFilterVisitor visitor) Visit this and all joined or nested table filters.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.h2.table.ColumnResolver
optimize
-
Field Details
-
ORDER_IN_FROM_COMPARATOR
Comparator that uses order in FROM clause as a sort key. -
joinOuterIndirect
protected boolean joinOuterIndirectWhether this is a direct or indirect (nested) outer join
-
-
Constructor Details
-
TableFilter
public TableFilter(SessionLocal session, Table table, String alias, boolean rightsChecked, Select select, int orderInFrom, IndexHints indexHints) Create a new table filter object.- Parameters:
session- the sessiontable- the table from where to read dataalias- the alias namerightsChecked- true if rights are already checkedselect- the select statementorderInFrom- original order number (index) of this table filter inindexHints- the index hints to be used by the query planner
-
-
Method Details
-
getOrderInFrom
public int getOrderInFrom()Get the order number (index) of this table filter in the "from" clause of the query.- Returns:
- the index (0, 1, 2,...)
-
getIndexCursor
-
getSelect
Description copied from interface:ColumnResolverGet the select statement.- Specified by:
getSelectin interfaceColumnResolver- Returns:
- the select statement
-
getTable
-
lock
Lock the table. This will also lock joined tables.- Parameters:
s- the session
-
getBestPlanItem
public PlanItem getBestPlanItem(SessionLocal s, TableFilter[] filters, int filter, AllColumnsForPlan allColumnsSet) Get the best plan item (index, cost) to use for the current join order.- Parameters:
s- the sessionfilters- all joined table filtersfilter- the current table filter indexallColumnsSet- the set of all columns- Returns:
- the best plan item
-
setPlanItem
Set what plan item (index, cost, masks) to use.- Parameters:
item- the plan item
-
prepare
public void prepare()Prepare reading rows. This method will remove all index conditions that can not be used, and optimize the conditions. -
startQuery
Start the query. This will reset the scan counts.- Parameters:
s- the session
-
reset
public void reset()Reset to the current position. -
next
public boolean next()Check if there are more rows to read.- Returns:
- true if there are
-
isNullRow
public boolean isNullRow() -
setNullRow
protected void setNullRow()Set the state of this and all nested tables to the NULL row. -
get
Get the current row.- Returns:
- the current row, or null
-
set
Set the current row.- Parameters:
current- the current row
-
getTableAlias
Get the table alias name. If no alias is specified, the table name is returned.- Specified by:
getTableAliasin interfaceColumnResolver- Returns:
- the alias name
-
addIndexCondition
Add an index condition.- Parameters:
condition- the index condition
-
addFilterCondition
Add a filter condition.- Parameters:
condition- the conditionisJoin- if this is in fact a join condition
-
addJoin
Add a joined table.- Parameters:
filter- the joined table filterouter- if this is an outer joinon- the join condition
-
setNestedJoin
Set a nested joined table.- Parameters:
filter- the joined table filter
-
mapAndAddFilter
Map the columns and add the join condition.- Parameters:
on- the condition
-
createIndexConditions
public void createIndexConditions()Create the index conditions for this filter if needed. -
getJoin
-
isJoinOuter
public boolean isJoinOuter()Whether this is an outer joined table.- Returns:
- true if it is
-
isJoinOuterIndirect
public boolean isJoinOuterIndirect()Whether this is indirectly an outer joined table (nested within an inner join).- Returns:
- true if it is
-
getPlanSQL
Get the query execution plan text to use for this table filter and append it to the specified builder.- Parameters:
builder- string builder to append toisJoin- if this is a joined tablesqlFlags- formatting flags- Returns:
- the specified builder
-
getMasks
public int[] getMasks() -
getIndexConditions
-
getIndex
-
setIndex
-
setUsed
public void setUsed(boolean used) -
isUsed
public boolean isUsed() -
removeJoin
public void removeJoin()Remove the joined table -
getJoinCondition
-
removeJoinCondition
public void removeJoinCondition()Remove the join condition. -
getFilterCondition
-
removeFilterCondition
public void removeFilterCondition()Remove the filter condition. -
setFullCondition
-
setEvaluatable
Update the filter and join conditions of this and all joined tables with the information that the given table filter and all nested filter can now return rows or not.- Parameters:
filter- the table filterb- the new flag
-
setEvaluatable
public void setEvaluatable(boolean evaluatable) -
getSchemaName
Description copied from interface:ColumnResolverGet the schema name or null.- Specified by:
getSchemaNamein interfaceColumnResolver- Returns:
- the schema name or null
-
getColumns
Description copied from interface:ColumnResolverGet the column list.- Specified by:
getColumnsin interfaceColumnResolver- Returns:
- the column list
-
findColumn
Description copied from interface:ColumnResolverGet the column with the specified name.- Specified by:
findColumnin interfaceColumnResolver- Parameters:
name- the column name, must be a derived name if this column resolver has a derived column list- Returns:
- the column with the specified name, or
null
-
getColumnName
Description copied from interface:ColumnResolverGet the name of the specified column.- Specified by:
getColumnNamein interfaceColumnResolver- Parameters:
column- column- Returns:
- column name
-
hasDerivedColumnList
public boolean hasDerivedColumnList()Description copied from interface:ColumnResolverReturns whether this column resolver has a derived column list.- Specified by:
hasDerivedColumnListin interfaceColumnResolver- Returns:
trueif this column resolver has a derived column list,falseotherwise
-
getColumn
Get the column with the given name.- Parameters:
columnName- the column nameifExists- iftruereturnnullif column does not exist- Returns:
- the column
- Throws:
DbException- if the column was not found andifExistsisfalse
-
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:
getSystemColumnsin interfaceColumnResolver- Returns:
- the system columns
-
getRowIdColumn
Description copied from interface:ColumnResolverGet the row id pseudo column, if there is one.- Specified by:
getRowIdColumnin interfaceColumnResolver- Returns:
- the row id column or null
-
getValue
Description copied from interface:ColumnResolverGet the value for the given column.- Specified by:
getValuein interfaceColumnResolver- Parameters:
column- the column- Returns:
- the value
-
getTableFilter
Description copied from interface:ColumnResolverGet the table filter.- Specified by:
getTableFilterin interfaceColumnResolver- Returns:
- the table filter
-
setAlias
-
setDerivedColumns
Set derived column list.- Parameters:
derivedColumnNames- names of derived columns
-
toString
-
addCommonJoinColumns
public void addCommonJoinColumns(Column leftColumn, Column replacementColumn, TableFilter replacementFilter) Add a column to the common join column list for a left table filter.- Parameters:
leftColumn- the column on the left sidereplacementColumn- the column to use instead, may be the same as column on the left sidereplacementFilter- the table filter for replacement columns
-
addCommonJoinColumnToExclude
Add an excluded column to the common join column list.- Parameters:
columnToExclude- the column to exclude
-
getCommonJoinColumns
Returns common join columns map.- Returns:
- common join columns map, or
null
-
getCommonJoinColumnsFilter
Returns common join columns table filter.- Returns:
- common join columns table filter, or
null
-
isCommonJoinColumnToExclude
Check if the given column is an excluded common join column.- Parameters:
c- the column to check- Returns:
- true if this is an excluded common join column
-
hashCode
public int hashCode() -
hasInComparisons
public boolean hasInComparisons()Are there any index conditions that involve IN(...).- Returns:
- whether there are IN(...) comparisons
-
getNestedJoin
-
visit
Visit this and all joined or nested table filters.- Parameters:
visitor- the visitor
-
isEvaluatable
public boolean isEvaluatable() -
getSession
-
getIndexHints
-
isNoFromClauseFilter
public boolean isNoFromClauseFilter()Returns whether this is a table filter with implicit DUAL table for a SELECT without a FROM clause.- Returns:
- whether this is a table filter with implicit DUAL table
-