|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.sql.compile.QueryTreeNode
org.apache.derby.impl.sql.compile.ResultSetNode
org.apache.derby.impl.sql.compile.FromTable
org.apache.derby.impl.sql.compile.TableOperatorNode
org.apache.derby.impl.sql.compile.SetOperatorNode
abstract class SetOperatorNode
A SetOperatorNode represents a UNION, INTERSECT, or EXCEPT in a DML statement. Binding and optimization preprocessing is the same for all of these operations, so they share bind methods in this abstract class. The class contains a boolean telling whether the operation should eliminate duplicate rows.
Field Summary | |
---|---|
(package private) boolean |
all
Tells whether to eliminate duplicate rows. |
(package private) ValueNode |
fetchFirst
|
private PredicateList |
leftOptPredicates
|
private java.util.HashMap |
leftScopedPreds
|
(package private) ValueNode |
offset
|
(package private) OrderByList |
orderByList
|
private PredicateList |
pushedPredicates
|
private PredicateList |
rightOptPredicates
|
private java.util.HashMap |
rightScopedPreds
|
Fields inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode |
---|
leftOptimizer, leftResultSet, rightOptimizer, rightResultSet |
Fields inherited from class org.apache.derby.impl.sql.compile.FromTable |
---|
ADD_PLAN, bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, LOAD_PLAN, loadFactor, maxCapacity, origTableName, REMOVE_PLAN, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategy |
Fields inherited from class org.apache.derby.impl.sql.compile.ResultSetNode |
---|
costEstimate, cursorTargetTable, finalCostEstimate, insertSource, optimizer, referencedTableMap, resultColumns, resultSetNumber, scratchCostEstimate, statementResultSet |
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode |
---|
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired |
Constructor Summary | |
---|---|
SetOperatorNode()
|
Method Summary | |
---|---|
void |
bindResultColumns(FromList fromListParam)
Bind the result columns of this ResultSetNode when there is no base table to bind them to. |
void |
bindResultColumns(TableDescriptor targetTableDescriptor,
FromVTI targetVTI,
ResultColumnList targetColumnList,
DMLStatementNode statement,
FromList fromListParam)
Bind the result columns for this ResultSetNode to a base table. |
void |
bindTargetExpressions(FromList fromListParam)
Bind the expressions in the target list. |
void |
bindUntypedNullsToResultColumns(ResultColumnList rcl)
Bind the result columns of a table constructor to the types in the given ResultColumnList. |
private void |
buildRCL()
Build the RCL for this node. |
ResultSetNode |
ensurePredicateList(int numTables)
Ensure that the top of the RSN tree has a PredicateList. |
boolean |
flattenableInFromSubquery(FromList fromList)
Evaluate whether or not the subquery in a FromSubquery is flattenable. |
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. |
(package private) PredicateList |
getLeftOptPredicateList()
Retrieve the list of optimizable predicates that are targeted for the left child. |
(package private) abstract java.lang.String |
getOperatorName()
|
(package private) int |
getParamColumnTypes(DataTypeDescriptor[] types,
RowResultSetNode rrsn)
Get the parameter types from the given RowResultSetNode into the given array of types. |
(package private) PredicateList |
getRightOptPredicateList()
Retrieve the list of optimizable predicates that are targeted for the right child. |
protected boolean |
hasUnPushedPredicates()
It's possible that we tried to push predicates to this node's children but failed to do so. |
void |
init(java.lang.Object leftResult,
java.lang.Object rightResult,
java.lang.Object all,
java.lang.Object tableProperties)
Initializer for a SetOperatorNode. |
Optimizable |
modifyAccessPath(JBitSet outerTables,
PredicateList predList)
|
boolean |
performMaterialization(JBitSet outerTables)
Return whether or not to materialize this ResultSet tree. |
ResultSetNode |
preprocess(int numTables,
GroupByList gbl,
FromList fromList)
Put a ProjectRestrictNode on top of each FromTable in the FromList. |
void |
printSubNodes(int depth)
Prints the sub-nodes of this object. |
void |
pullOptPredicates(OptimizablePredicateList optimizablePredicates)
Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList. |
(package private) void |
pushOffsetFetchFirst(ValueNode offset,
ValueNode fetchFirst)
Push down the offset and fetch first parameters, if any, to this node. |
boolean |
pushOptPredicate(OptimizablePredicate optimizablePredicate)
Push an OptimizablePredicate down, if this node accepts it. |
(package private) void |
pushOrderByList(OrderByList orderByList)
Push the order by list down from the cursor node into its child result set so that the optimizer has all of the information that it needs to consider sort avoidance. |
(package private) void |
replaceOrForbidDefaults(TableDescriptor ttd,
ResultColumnList tcl,
boolean allowDefaults)
Replace any DEFAULTs with the associated tree for the default if allowed, or flag (when inside top level set operator nodes). |
(package private) void |
setParamColumnTypes(DataTypeDescriptor[] types,
RowResultSetNode rrsn)
Set the type of each ? |
ResultSetNode |
setResultToBooleanTrueNode(boolean onlyConvertAlls)
Set the result column for the subquery to a boolean true, Useful for transformations such as changing: where exists (select ... from ...) |
java.lang.String |
toString()
Convert this object to a String. |
void |
verifySelectStarSubquery(FromList outerFromList,
int subqueryType)
Verify that a SELECT * is valid for this type of subquery. |
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.Optimizable |
---|
getDataDictionary, getReferencedTableMap, getResultSetNumber |
Field Detail |
---|
boolean all
OrderByList orderByList
ValueNode offset
ValueNode fetchFirst
private PredicateList leftOptPredicates
private PredicateList rightOptPredicates
private PredicateList pushedPredicates
private java.util.HashMap leftScopedPreds
private java.util.HashMap rightScopedPreds
Constructor Detail |
---|
SetOperatorNode()
Method Detail |
---|
public void init(java.lang.Object leftResult, java.lang.Object rightResult, java.lang.Object all, java.lang.Object tableProperties) throws StandardException
init
in class QueryTreeNode
leftResult
- The ResultSetNode on the left side of this unionrightResult
- The ResultSetNode on the right side of this unionall
- Whether or not this is an ALL.tableProperties
- Properties list associated with the table
StandardException
- Thrown on errorpublic Optimizable modifyAccessPath(JBitSet outerTables, PredicateList predList) throws StandardException
StandardException
- Thrown on errorOptimizable.modifyAccessPath(org.apache.derby.iapi.util.JBitSet)
public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate) throws StandardException
Optimizable
pushOptPredicate
in interface Optimizable
pushOptPredicate
in class FromTable
optimizablePredicate
- OptimizablePredicate to push down.
StandardException
- Thrown on errorTake a predicate and push it down to both the left AND right result
sets. Return "true" if we successfully pushed it to both sides,
and "false" otherwise. The assumption is that if we return "true",
the caller will take the predicate and remove it from its own list
of predicates to evaluate; if we return false, then the predicate
will be evaluated at the level of the caller. So returning "false"
means that the left and right result sets for this node will be fully
returned, and then the predicate will be evaluated against the
of those result sets (as of DERBY-805, the only set
operator calling this method is UnionNode). If we can push the
predicate down to both children, though, we can evaluate it closer
to store, which means that each child result set returns only the
correctly qualified rows, and thus the calling set operator will
have a smaller result set on which to operate, which can boost
performance.
That said, if we can't push the predicate to _both_ sides, we don't
push it at all. The reason is that if we push to one side but not
to the other, we would have to ask the question of whether we should
return "true" (meaning that the predicate would be removed from the
caller's list and thus would _not_ be evaluated at the
level) or "false" (meaning that the caller would keep the predicate
and evaluate it at the level). Depending on the query
in question, both answers could end up returning incorrect results.
For example, if we push it to the right but not to the left, then
leave it in the caller's list, the optimizer for the caller might
decide to use the predicate to do a hash join with some outer result
set (if the predicate is an equijoin predicate). That would result
in materialization of the calling node and of its children--but since
we pushed a predicate that depends on the outer table down into the
right child, materialization of the right child will only return the
rows that join with the _first_ row of the outer result set, which
is wrong.
If, on the other hand, we push the predicate to one side and then tell
the caller to remove it from its list, the side to which we did _not_
push the predicate could return rows that aren't qualified. Then,
since the caller removed the predicate from its list, it (the caller)
will not evaluate the predicate on its own result set--and thus we
can end up returning rows that we weren't supposed to return.
So all of that said, only push (and return "true") if we think we
can push the predicate to both sides.
public void pullOptPredicates(OptimizablePredicateList optimizablePredicates) throws StandardException
Optimizable
pullOptPredicates
in interface Optimizable
pullOptPredicates
in class FromTable
optimizablePredicates
- The list to put the pulled predicates
in.
StandardException
- Thrown on errorOptimizable.pullOptPredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)
protected boolean hasUnPushedPredicates()
public java.lang.String toString()
toString
in class TableOperatorNode
public void printSubNodes(int depth)
printSubNodes
in class TableOperatorNode
depth
- The depth of this node in the treepublic void bindResultColumns(FromList fromListParam) throws StandardException
bindResultColumns
in class TableOperatorNode
fromListParam
- FromList to use/append to.
StandardException
- Thrown on errorpublic void bindResultColumns(TableDescriptor targetTableDescriptor, FromVTI targetVTI, ResultColumnList targetColumnList, DMLStatementNode statement, FromList fromListParam) throws StandardException
bindResultColumns
in class TableOperatorNode
targetTableDescriptor
- The TableDescriptor for the table being
updated or inserted intotargetColumnList
- For INSERT statements, the user
does not have to supply column
names (for example, "insert into t
values (1,2,3)". When this
parameter is null, it means that
the user did not supply column
names, and so the binding should
be done based on order. When it
is not null, it means do the binding
by name, not position.statement
- Calling DMLStatementNode (Insert or Update)fromListParam
- FromList to use/append to.
StandardException
- Thrown on errorprivate void buildRCL() throws StandardException
StandardException
- Thrown on errorpublic void bindUntypedNullsToResultColumns(ResultColumnList rcl) throws StandardException
bindUntypedNullsToResultColumns
in class TableOperatorNode
rcl
- The ResultColumnList with the types to bind to
StandardException
- Thrown on error.void replaceOrForbidDefaults(TableDescriptor ttd, ResultColumnList tcl, boolean allowDefaults) throws StandardException
replaceOrForbidDefaults
in class ResultSetNode
ttd
- The TableDescriptor for the target table.tcl
- The RCL for the target table.allowDefaults
- true if allowed
StandardException
- Thrown on errorint getParamColumnTypes(DataTypeDescriptor[] types, RowResultSetNode rrsn) throws StandardException
types
- The array of types to fill inrrsn
- The RowResultSetNode from which to take the param types
StandardException
void setParamColumnTypes(DataTypeDescriptor[] types, RowResultSetNode rrsn) throws StandardException
types
- An array of types containing the proper type for each
? parameter, by ordinal position.rrsn
- A RowResultSetNode that could contain ? parameters whose
types need to be set.
StandardException
- Thrown on errorpublic void bindTargetExpressions(FromList fromListParam) throws StandardException
bindTargetExpressions
in class ResultSetNode
StandardException
- Thrown on errorvoid pushOrderByList(OrderByList orderByList)
pushOrderByList
in class ResultSetNode
orderByList
- The order by listvoid pushOffsetFetchFirst(ValueNode offset, ValueNode fetchFirst)
pushOffsetFetchFirst
in class ResultSetNode
offset
- the OFFSET, if anyfetchFirst
- the OFFSET FIRST, if anypublic ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException
preprocess
in class TableOperatorNode
numTables
- Number of tables in the DML Statementgbl
- The group by list, if anyfromList
- The from list, if any
StandardException
- Thrown on errorpublic ResultSetNode ensurePredicateList(int numTables) throws StandardException
ensurePredicateList
in class ResultSetNode
numTables
- The number of tables in the query.
StandardException
- Thrown on errorpublic void verifySelectStarSubquery(FromList outerFromList, int subqueryType) throws StandardException
verifySelectStarSubquery
in class ResultSetNode
outerFromList
- The FromList from the outer query block(s)subqueryType
- The subquery type
StandardException
- Thrown on errorprotected FromTable getFromTableByName(java.lang.String name, java.lang.String schemaName, boolean exactMatch) throws StandardException
getFromTableByName
in class TableOperatorNode
name
- The specified name to search for as an exposed name.schemaName
- Schema name, if non-null.exactMatch
- Whether or not we need an exact match on specified schema and table
names or match on table id.
StandardException
- Thrown on errorpublic ResultSetNode setResultToBooleanTrueNode(boolean onlyConvertAlls) throws StandardException
setResultToBooleanTrueNode
in class ResultSetNode
onlyConvertAlls
- Boolean, whether or not to just convert *'s
StandardException
- Thrown on errorpublic boolean flattenableInFromSubquery(FromList fromList)
flattenableInFromSubquery
in class ResultSetNode
fromList
- The outer from list
public boolean performMaterialization(JBitSet outerTables) throws StandardException
performMaterialization
in class ResultSetNode
StandardException
- Thrown on errorabstract java.lang.String getOperatorName()
PredicateList getLeftOptPredicateList() throws StandardException
StandardException
PredicateList getRightOptPredicateList() throws StandardException
StandardException
|
Built on Thu 2012-03-29 21:53:33+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |