|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> sql >> [ compile overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.impl.sql.compile
Class FromList

java.lang.Objectorg.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.QueryTreeNodeVector
org.apache.derby.impl.sql.compile.FromList
- All Implemented Interfaces:
- org.apache.derby.iapi.sql.compile.OptimizableList, org.apache.derby.iapi.sql.compile.Visitable
- public class FromList
- extends QueryTreeNodeVector
- implements org.apache.derby.iapi.sql.compile.OptimizableList
- extends QueryTreeNodeVector
A FromList represents the list of tables in a FROM clause in a DML statement. It extends QueryTreeNodeVector.
| Field Summary | |
(package private) boolean |
fixedJoinOrder
|
(package private) java.util.Properties |
properties
|
(package private) boolean |
useStatistics
|
| Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode |
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset |
| Constructor Summary | |
FromList()
|
|
| Method Summary | |
org.apache.derby.iapi.sql.compile.Visitable |
accept(org.apache.derby.iapi.sql.compile.Visitor v)
Accept a visitor, and call v.visit() on child nodes as necessary. |
void |
addElement(QueryTreeNode qt)
|
void |
addFromTable(FromTable fromTable)
Add a table to the FROM list. |
ResultColumn |
bindColumnReference(ColumnReference columnReference)
Bind a column reference to one of the tables in this FromList. |
void |
bindExpressions()
Bind the expressions in this FromList. |
void |
bindResultColumns(FromList fromListParam)
Bind the result columns of the ResultSetNodes in this FromList when there is no base table to bind them to. |
void |
bindTables(org.apache.derby.iapi.sql.dictionary.DataDictionary dataDictionary,
FromList fromListParam)
Bind the tables in this FromList. |
void |
bindUntypedNullsToResultColumns(ResultColumnList bindingRCL)
Bind any untyped null nodes to the types in the given ResultColumnList. |
(package private) void |
decrementLevel(int decrement)
Decrement (query block) level (0-based) for all of the tables in this from list. |
void |
destructiveAppend(QueryTreeNodeVector qtnv)
|
QueryTreeNode |
elementAt(int index)
|
ResultColumnList |
expandAll(TableName allTableName)
Expand a "*" into the appropriate ResultColumnList. |
void |
flattenFromTables(ResultColumnList rcl,
PredicateList predicateList,
SubqueryList sql,
GroupByList gbl)
Flatten all the FromTables that are flattenable. |
(package private) void |
genExistsBaseTables(org.apache.derby.iapi.util.JBitSet referencedTableMap,
FromList outerFromList,
boolean isNotExists)
Mark all of the FromBaseTables in the list as EXISTS FBTs. |
protected FromTable |
getFromTableByName(java.lang.String name,
java.lang.String schemaName,
boolean exactMatch)
Determine whether or not the specified name is an exposed name in the current query block. |
FromTable |
getFromTableByResultColumn(ResultColumn rc)
Get the FromTable from this list which has the specified ResultColumn in its RCL. |
org.apache.derby.iapi.sql.compile.Optimizable |
getOptimizable(int index)
Return the nth Optimizable in the list. |
(package private) int[] |
getTableNumbers()
|
(package private) boolean |
hashJoinSpecified()
Return whether or not the user specified a hash join for any of the tables in this list. |
boolean |
hasOuterJoins()
Returns true if any Outer joins present. |
(package private) int |
indexOf(QueryTreeNode qt)
|
void |
init(java.lang.Object optimizeJoinOrder)
Initializer for a FromList |
void |
init(java.lang.Object optimizeJoinOrder,
java.lang.Object fromTable)
Initializer for a FromList |
void |
initAccessPaths(org.apache.derby.iapi.sql.compile.Optimizer optimizer)
Init the access paths for these optimizables. |
(package private) void |
insertElementAt(QueryTreeNode qt,
int index)
|
boolean |
legalJoinOrder(int numTablesInQuery)
Tell whether the join order is legal. |
boolean |
LOJ_reorderable(int numTables)
|
(package private) void |
markStatementResultSet()
Move the mark for result set being the statement's outermost result set down into the first table of the from list. |
void |
nondestructiveAppend(QueryTreeNodeVector qtnv)
|
boolean |
optimizeJoinOrder()
Tell whether the join order should be optimized. |
void |
preprocess(int numTables,
GroupByList gbl,
ValueNode predicateTree)
Preprocess the query tree - this currently means: o Generating a referenced table map for each ResultSetNode. |
void |
printSubNodes(int depth)
Prints the sub-nodes of this object. |
(package private) void |
pushPredicates(PredicateList predicateList)
Categorize and push the predicates that are pushable. |
boolean |
referencesSessionSchema()
Return true if the node references SESSION schema tables (temporary or permanent) |
boolean |
referencesTarget(java.lang.String name,
boolean baseTable)
Search to see if a query references the specifed table name. |
void |
rejectParameters()
Check for (and reject) all ? parameters directly under the ResultColumns. |
(package private) java.lang.Object |
remove(int index)
|
(package private) void |
removeAllElements()
|
(package private) void |
removeElement(QueryTreeNode qt)
|
(package private) void |
removeElementAt(int index)
|
void |
reOrder(int[] joinOrder)
Set the join order for this list of optimizables. |
(package private) boolean |
returnsAtMostSingleRow(ResultColumnList rcl,
ValueNode whereClause,
PredicateList wherePredicates,
org.apache.derby.iapi.sql.dictionary.DataDictionary dd)
This method is used for both subquery flattening and distinct elimination based on a uniqueness condition. |
(package private) void |
setElementAt(QueryTreeNode qt,
int index)
|
void |
setLevel(int level)
Set the (query block) level (0-based) for the FromTables in this FromList. |
void |
setOptimizable(int index,
org.apache.derby.iapi.sql.compile.Optimizable optimizable)
Set the nth Optimizable to the specified Optimizable. |
void |
setProperties(java.util.Properties props)
Set the Properties list for this FromList. |
int |
size()
Return the number of Optimizables in the list. |
java.lang.String |
toString()
Format this list as a string We can simply iterate through the list. |
int |
updateTargetLockMode()
Get the lock mode for the target of an update statement (a delete or update). |
boolean |
useStatistics()
user can specify that s/he doesn't want statistics to be considered when optimizing the query. |
void |
verifyProperties(org.apache.derby.iapi.sql.dictionary.DataDictionary dDictionary)
Verify that the Properties list with optimizer overrides, if specified, is valid |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.apache.derby.iapi.sql.compile.OptimizableList |
size |
| Field Detail |
properties
java.util.Properties properties
fixedJoinOrder
boolean fixedJoinOrder
useStatistics
boolean useStatistics
| Constructor Detail |
FromList
public FromList()
| Method Detail |
init
public void init(java.lang.Object optimizeJoinOrder)
- Initializer for a FromList
- Overrides:
initin classQueryTreeNode
init
public void init(java.lang.Object optimizeJoinOrder, java.lang.Object fromTable) throws org.apache.derby.iapi.error.StandardException
- Initializer for a FromList
- Overrides:
initin classQueryTreeNode
getOptimizable
public org.apache.derby.iapi.sql.compile.Optimizable getOptimizable(int index)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - Return the nth Optimizable in the list.
- Specified by:
getOptimizablein interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
setOptimizable
public void setOptimizable(int index,
org.apache.derby.iapi.sql.compile.Optimizable optimizable)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - Set the nth Optimizable to the specified Optimizable.
- Specified by:
setOptimizablein interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
verifyProperties
public void verifyProperties(org.apache.derby.iapi.sql.dictionary.DataDictionary dDictionary) throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - Verify that the Properties list with optimizer overrides, if specified, is valid
- Specified by:
verifyPropertiesin interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
addFromTable
public void addFromTable(FromTable fromTable) throws org.apache.derby.iapi.error.StandardException
- Add a table to the FROM list.
referencesTarget
public boolean referencesTarget(java.lang.String name, boolean baseTable) throws org.apache.derby.iapi.error.StandardException
- Search to see if a query references the specifed table name.
referencesSessionSchema
public boolean referencesSessionSchema()
throws org.apache.derby.iapi.error.StandardException
- Return true if the node references SESSION schema tables (temporary or permanent)
- Overrides:
referencesSessionSchemain classQueryTreeNode
getFromTableByName
protected FromTable getFromTableByName(java.lang.String name, java.lang.String schemaName, boolean exactMatch) throws org.apache.derby.iapi.error.StandardException
- Determine whether or not the specified name is an exposed name in
the current query block.
bindTables
public void bindTables(org.apache.derby.iapi.sql.dictionary.DataDictionary dataDictionary, FromList fromListParam) throws org.apache.derby.iapi.error.StandardException
- Bind the tables in this FromList. This includes looking them up in
the DataDictionary, getting their TableDescriptors and assigning the
table numbers.
bindExpressions
public void bindExpressions()
throws org.apache.derby.iapi.error.StandardException
- Bind the expressions in this FromList. This means
binding the sub-expressions, as well as figuring out what the return
type is for each expression.
bindResultColumns
public void bindResultColumns(FromList fromListParam) throws org.apache.derby.iapi.error.StandardException
- Bind the result columns of the ResultSetNodes in this FromList when there is no
base table to bind them to. This is useful for SELECT statements,
where the result columns get their types from the expressions that
live under them.
hasOuterJoins
public boolean hasOuterJoins()
throws org.apache.derby.iapi.error.StandardException
- Returns true if any Outer joins present. Used to set Nullability
expandAll
public ResultColumnList expandAll(TableName allTableName) throws org.apache.derby.iapi.error.StandardException
- Expand a "*" into the appropriate ResultColumnList. If the "*"
is unqualified it will expand into a list of all columns in all
of the base tables in the from list, otherwise it will expand
into a list of all of the columns in the base table that matches
the qualification.
bindColumnReference
public ResultColumn bindColumnReference(ColumnReference columnReference) throws org.apache.derby.iapi.error.StandardException
- Bind a column reference to one of the tables in this FromList. The column name
must be unique within the tables in the FromList. An exception is thrown
if a column name is not unique.
NOTE: Callers are responsible for ordering the FromList by nesting level,
with tables at the deepest (current) nesting level first. We will try to
match against all FromTables at a given nesting level. If no match is
found at a nesting level, then we proceed to the next level. We stop
walking the list when the nesting level changes and we have found a match.
NOTE: If the ColumnReference is qualified, then we will stop the search
at the first nesting level where there is a match on the exposed table name.
For example, s (a, b, c), t (d, e, f)
select * from s where exists (select * from t s where s.c = a)
will not find a match for s.c, which is the expected ANSI behavior.
bindTables() must have already been called on this FromList before
calling this method.
rejectParameters
public void rejectParameters()
throws org.apache.derby.iapi.error.StandardException
- Check for (and reject) all ? parameters directly under the ResultColumns.
This is done for SELECT statements.
LOJ_reorderable
public boolean LOJ_reorderable(int numTables)
throws org.apache.derby.iapi.error.StandardException
preprocess
public void preprocess(int numTables,
GroupByList gbl,
ValueNode predicateTree)
throws org.apache.derby.iapi.error.StandardException
- Preprocess the query tree - this currently means:
o Generating a referenced table map for each ResultSetNode.
o Putting the WHERE and HAVING clauses in conjunctive normal form (CNF).
o Converting the WHERE and HAVING clauses into PredicateLists and
classifying them.
o Flatten those FromSubqueries which can be flattened.
o Ensuring that a ProjectRestrictNode is generated on top of every
FromBaseTable and generated in place of every FromSubquery which
could not be flattened.
o Pushing single table predicates down to the new ProjectRestrictNodes.
flattenFromTables
public void flattenFromTables(ResultColumnList rcl, PredicateList predicateList, SubqueryList sql, GroupByList gbl) throws org.apache.derby.iapi.error.StandardException
- Flatten all the FromTables that are flattenable.
RESOLVE - right now we just flatten FromSubqueries. We
should also flatten flattenable JoinNodes here.
pushPredicates
void pushPredicates(PredicateList predicateList) throws org.apache.derby.iapi.error.StandardException
- Categorize and push the predicates that are pushable.
printSubNodes
public void printSubNodes(int depth)
- Prints the sub-nodes of this object. See QueryTreeNode.java for
how tree printing is supposed to work.
- Overrides:
printSubNodesin classQueryTreeNode
setLevel
public void setLevel(int level)
- Set the (query block) level (0-based) for the FromTables in this
FromList.
markStatementResultSet
void markStatementResultSet()
- Move the mark for result set being the statement's outermost
result set down into the first table of the from list.
Generally expect there is only one table at this point.
getFromTableByResultColumn
public FromTable getFromTableByResultColumn(ResultColumn rc)
- Get the FromTable from this list which has the specified ResultColumn in
its RCL.
setProperties
public void setProperties(java.util.Properties props) throws org.apache.derby.iapi.error.StandardException
- Set the Properties list for this FromList.
reOrder
public void reOrder(int[] joinOrder)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - Set the join order for this list of optimizables. The join order is
represented as an array of integers - each entry in the array stands
for the order of the corresponding element in the list. For example,
a joinOrder of {2, 0, 1} means that the 3rd Optimizable in the list
(element 2, since we are zero-based) is the first one in the join
order, followed by the 1st element in the list, and finally by the
2nd element in the list.
This method shuffles this OptimizableList to match the join order.
Obviously, the size of the array must equal the number of elements in
the array, and the values in the array must be between 0 and the
number of elements in the array minus 1, and the values in the array
must be unique.
- Specified by:
reOrderin interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
useStatistics
public boolean useStatistics()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - user can specify that s/he doesn't want statistics to be considered when
optimizing the query.
- Specified by:
useStatisticsin interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
optimizeJoinOrder
public boolean optimizeJoinOrder()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - Tell whether the join order should be optimized.
- Specified by:
optimizeJoinOrderin interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
legalJoinOrder
public boolean legalJoinOrder(int numTablesInQuery)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - Tell whether the join order is legal.
- Specified by:
legalJoinOrderin interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
initAccessPaths
public void initAccessPaths(org.apache.derby.iapi.sql.compile.Optimizer optimizer)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.OptimizableList - Init the access paths for these optimizables.
- Specified by:
initAccessPathsin interfaceorg.apache.derby.iapi.sql.compile.OptimizableList
bindUntypedNullsToResultColumns
public void bindUntypedNullsToResultColumns(ResultColumnList bindingRCL) throws org.apache.derby.iapi.error.StandardException
- Bind any untyped null nodes to the types in the given ResultColumnList.
decrementLevel
void decrementLevel(int decrement)
- Decrement (query block) level (0-based) for
all of the tables in this from list.
This is useful when flattening a subquery.
returnsAtMostSingleRow
boolean returnsAtMostSingleRow(ResultColumnList rcl, ValueNode whereClause, PredicateList wherePredicates, org.apache.derby.iapi.sql.dictionary.DataDictionary dd) throws org.apache.derby.iapi.error.StandardException
- This method is used for both subquery flattening and distinct
elimination based on a uniqueness condition. For subquery
flattening we want to make sure that the query block
will return at most 1 row. For distinct elimination we
want to make sure that the query block will not return
any duplicates.
This is true if every table in the from list is
(a base table and the set of columns from the table that
are in equality comparisons with expressions that do not include columns
from the same table is a superset of any unique index
on the table) or an EXISTS FBT. In addition, at least 1 of the tables
in the list has a set of columns in equality comparisons with expressions
that do not include column references from the same query block
is a superset of a unique index
on that table. (This ensures that the query block will onlyr
return a single row.)
This method is expected to be called after normalization and
after the from list has been preprocessed.
It can be called both before and after the predicates have
been pulled from the where clause.
The algorithm for this is as follows
If any table in the query block is not a base table, give up.
For each table in the query
Ignore exists table since they can only produce one row
create a matrix of tables and columns from the table (tableColMap)
(this is used to keep track of the join columns and constants
that can be used to figure out whether the rows from a join
or in a select list are distinct based on unique indexes)
create an array of columns from the table(eqOuterCol)
(this is used to determine that only one row will be returned
from a join)
if the current table is the table for the result columns
set the result columns in the eqOuterCol and tableColMap
(if these columns are a superset of a unique index and
all joining tables result in only one row, the
results will be distinct)
go through all the predicates and update tableColMap and
eqOuterCol with join columns and correlation variables,
parameters and constants
since setting constants, correlation variables and parameters,
reduces the number of columns required for uniqueness in a
multi-column index, they are set for all the tables (if the
table is not the result table, in this case only the column of the
result table is set)
join columns are just updated for the column in the row of the
joining table.
check if the marked columns in tableColMap are a superset of a unique
index
(This means that the join will only produce 1 row when joined
with 1 row of another table)
check that there is a least one table for which the columns in
eqOuterCol(i.e. constant values) are a superset of a unique index
(This quarantees that there will be only one row selected
from this table).
Once all tables have been evaluated, check that all the tables can be
joined by unique index or will have only one row
getTableNumbers
int[] getTableNumbers()
genExistsBaseTables
void genExistsBaseTables(org.apache.derby.iapi.util.JBitSet referencedTableMap, FromList outerFromList, boolean isNotExists) throws org.apache.derby.iapi.error.StandardException
- Mark all of the FromBaseTables in the list as EXISTS FBTs.
Each EBT has the same dependency list - those tables that are referenced
minus the tables in the from list.
updateTargetLockMode
public int updateTargetLockMode()
- Get the lock mode for the target of an update statement
(a delete or update). The update mode will always be row for
CurrentOfNodes. It will be table if there is no where clause.
hashJoinSpecified
boolean hashJoinSpecified()
- Return whether or not the user specified a hash join for any of the
tables in this list.
accept
public org.apache.derby.iapi.sql.compile.Visitable accept(org.apache.derby.iapi.sql.compile.Visitor v) throws org.apache.derby.iapi.error.StandardException
- Accept a visitor, and call v.visit()
on child nodes as necessary.
- Specified by:
acceptin interfaceorg.apache.derby.iapi.sql.compile.Visitable- Overrides:
acceptin classQueryTreeNodeVector
size
public final int size()
elementAt
public QueryTreeNode elementAt(int index)
addElement
public final void addElement(QueryTreeNode qt)
removeElementAt
final void removeElementAt(int index)
removeElement
final void removeElement(QueryTreeNode qt)
remove
final java.lang.Object remove(int index)
indexOf
final int indexOf(QueryTreeNode qt)
setElementAt
final void setElementAt(QueryTreeNode qt, int index)
destructiveAppend
public void destructiveAppend(QueryTreeNodeVector qtnv)
nondestructiveAppend
public void nondestructiveAppend(QueryTreeNodeVector qtnv)
removeAllElements
final void removeAllElements()
insertElementAt
final void insertElementAt(QueryTreeNode qt, int index)
toString
public java.lang.String toString()
- Format this list as a string
We can simply iterate through the list. Note each list member
is a QueryTreeNode, and so should have its specialization of
toString defined.
- Overrides:
toStringin classQueryTreeNode
|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> sql >> [ compile overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC