Class HalfOuterJoinNode
- java.lang.Object
-
- All Implemented Interfaces:
Optimizable
,Visitable
class HalfOuterJoinNode extends JoinNode
An HalfOuterJoinNode represents a left or a right outer join result set. Right outer joins are always transformed into left outer joins during preprocessing for simplicity.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
ResultSetNode.QueryExpressionClauses
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
rightOuterJoin
private boolean
transformed
-
Fields inherited from class org.apache.derby.impl.sql.compile.JoinNode
aggregates, CROSSJOIN, flattenableJoin, FULLOUTERJOIN, INNERJOIN, joinClause, joinClauseNormalized, joinOrderStrategyProperties, joinPredicates, LEFTOUTERJOIN, RIGHTOUTERJOIN, subqueryList, UNIONJOIN, usingClause
-
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.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description HalfOuterJoinNode(ResultSetNode leftResult, ResultSetNode rightResult, ValueNode onClause, ResultColumnList usingClause, boolean rightOuterJoin, java.util.Properties tableProperties, ContextManager cm)
Constructor for a HalfOuterJoinNode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) int
addOuterJoinArguments(ActivationClassBuilder acb, MethodBuilder mb)
Generate and add any arguments specifict to outer joins.protected void
adjustNumberOfRowsReturned(CostEstimate costEstimate)
Some types of joins (e.g. outer joins) will return a different number of rows than is predicted by optimizeIt() in JoinNode.(package private) void
generate(ActivationClassBuilder acb, MethodBuilder mb)
Generate the code for an inner join node.(package private) ResultSetNode
getLogicalLeftResultSet()
Return the logical left result set for this qualified join node.(package private) ResultSetNode
getLogicalRightResultSet()
Return the logical right result set for this qualified join node.protected int
getNumJoinArguments()
Return the number of arguments to the join result set.(package private) void
isJoinColumnForRightOuterJoin(ResultColumn rc)
If this is a right outer join node with USING/NATURAL clause, then check if the passed ResultColumn is a join column.private boolean
isNullRejecting(ValueNode joinClause, JBitSet leftTableMap, JBitSet rightTableMap)
Tests pRiRj in the sense of Galindo-Legaria et al: Outerjoin Simplification and Reordering for Query Optimization, ACM Transactions on Database Systems, Vol. 22, No. 1, March 1997, Pages 43-74:"The set of attributes referenced by a predicate p is called the schema of p, and denoted sch(p).
(package private) boolean
isRightOuterJoin()
Return true if right outer join or false if left outer join Used to set Nullability correctly in JoinNode(package private) boolean
LOJ_bindResultColumns(boolean anyChange)
(package private) boolean
LOJ_reorderable(int numTables)
This method recursively: determines if this part of the query tree is a compound OJ of the shape required for reordering and if so, does a reordering.(package private) JBitSet
LOJgetNPReferencedTables(int numTables)
JBitSet
LOJgetRPReferencedTables(int numTables)
(package private) void
oneRowRightSide(ActivationClassBuilder acb, MethodBuilder mb)
(package private) ResultSetNode
preprocess(int numTables, GroupByList gbl, FromList fromList)
Put a ProjectRestrictNode on top of each FromTable in the FromList.(package private) void
pushExpressions(PredicateList outerPredicateList)
Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map.boolean
pushOptPredicate(OptimizablePredicate optimizablePredicate)
Push an OptimizablePredicate down, if this node accepts it.java.lang.String
toString()
Convert this object to a String.(package private) FromTable
transformOuterJoins(ValueNode predicateTree, int numTables)
Transform any Outer Join into an Inner Join where applicable.-
Methods inherited from class org.apache.derby.impl.sql.compile.JoinNode
acceptChildren, bindExpression, bindExpressions, bindResultColumns, bindResultColumns, flatten, generateCore, generateCore, getAllResultColumns, getFinalCostEstimate, getLeftPredicateList, getMatchingColumn, getRightPredicateList, isFlattenableJoinNode, isOrderedOn, joinTypeToString, LOJgetReferencedTables, makeFromList, modifyAccessPath, normExpressions, notFlattenableJoin, optimizeIt, printSubNodes, projectResultColumns, pushExpressionsToLeft, setAggregates, setNaturalJoin, setSubqueryList, updateTargetLockMode
-
Methods inherited from class org.apache.derby.impl.sql.compile.TableOperatorNode
adjustForSortElimination, adjustForSortElimination, bindExpressionsWithTables, bindNonVTITables, bindUntypedNullsToResultColumns, bindVTITables, decrementLevel, getExposedName, getFromTableByName, getLeftmostResultSet, getLeftResultSet, getRightResultSet, modifyAccessPaths, needsSpecialRCLBinding, optimize, optimizeSource, referencesSessionSchema, referencesTarget, rejectParameters, setLeftmostResultSet, setLevel, setNestedInParens, setReferencedColumns, updateBestPlanMap, verifyProperties
-
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
assignCostEstimate, canBeOrdered, columnsAreUpdatable, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, feasibleJoinStrategy, fillInReferencedTableMap, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getLevel, getMergeTableID, getName, getNumColumnsReturned, getOrigTableName, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasLargeObjectColumns, hasTableNumber, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, markUpdatableByCursor, maxCapacity, memoryUsageOK, nextAccessPath, optimizeSubqueries, pullOptPredicates, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimateCost, setHashKeyColumns, setMergeTableID, setOrigTableName, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, uniqueJoin
-
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, assignResultSetNumber, bindTargetExpressions, changeAccessPath, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getCandidateFinalCostEstimate, getCostEstimate, getCursorTargetTable, getFromList, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, getScratchCostEstimate, isCursorTargetTable, isInsertSource, isNotExists, isOneRowResultSet, isPossibleDistinctScan, isStatementResultSet, isUpdatableCursor, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, notCursorTargetTable, numDistinctAggregates, parseDefault, performMaterialization, printQueryExpressionSuffixClauses, pushOffsetFetchFirst, pushOrderByList, pushQueryExpressionSuffix, rejectXMLValues, renameGeneratedResultNames, replaceOrForbidDefaults, returnsAtMostOneRow, setCandidateFinalCostEstimate, setCostEstimate, setCursorTargetTable, setInsertSource, setOptimizer, setReferencedTableMap, setResultColumns, setResultSetNumber, setResultToBooleanTrueNode, setScratchCostEstimate, setTableConstructorTypes, subqueryReferencesTarget, verifySelectStarSubquery
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
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, getOptimizerTracer, getReferencedTableMap, getResultSetNumber, optimizerTracingIsOn
-
Methods inherited from interface org.apache.derby.iapi.sql.compile.Visitable
accept, addTag, taggedWith
-
-
-
-
Constructor Detail
-
HalfOuterJoinNode
HalfOuterJoinNode(ResultSetNode leftResult, ResultSetNode rightResult, ValueNode onClause, ResultColumnList usingClause, boolean rightOuterJoin, java.util.Properties tableProperties, ContextManager cm) throws StandardException
Constructor for a HalfOuterJoinNode.- Parameters:
leftResult
- The ResultSetNode on the left side of this joinrightResult
- The ResultSetNode on the right side of this joinonClause
- The ON clauseusingClause
- The USING clauserightOuterJoin
- Whether or not this node represents a user specified right outer jointableProperties
- Properties list associated with the tablecm
- The context manager- Throws:
StandardException
- Thrown on error
-
-
Method Detail
-
pushOptPredicate
public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate) throws StandardException
Description copied from interface:Optimizable
Push an OptimizablePredicate down, if this node accepts it.- Specified by:
pushOptPredicate
in interfaceOptimizable
- Overrides:
pushOptPredicate
in classJoinNode
- Parameters:
optimizablePredicate
- OptimizablePredicate to push down.- Returns:
- Whether or not the predicate was pushed down.
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.pushOptPredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate)
-
toString
public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.- Overrides:
toString
in classTableOperatorNode
- Returns:
- This object as a String
-
preprocess
ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException
Put a ProjectRestrictNode on top of each FromTable in the FromList. ColumnReferences must continue to point to the same ResultColumn, so that ResultColumn must percolate up to the new PRN. However, that ResultColumn will point to a new expression, a VirtualColumnNode, which points to the FromTable and the ResultColumn that is the source for the ColumnReference. (The new PRN will have the original of the ResultColumnList and the ResultColumns from that list. The FromTable will get shallow copies of the ResultColumnList and its ResultColumns. ResultColumn.expression will remain at the FromTable, with the PRN getting a new VirtualColumnNode for each ResultColumn.expression.) We then project out the non-referenced columns. If there are no referenced columns, then the PRN's ResultColumnList will consist of a single ResultColumn whose expression is 1.- Overrides:
preprocess
in classJoinNode
- Parameters:
numTables
- Number of tables in the DML Statementgbl
- The group by list, if anyfromList
- The from list, if any- Returns:
- The generated ProjectRestrictNode atop the original FromTable.
- Throws:
StandardException
- Thrown on error
-
pushExpressions
void pushExpressions(PredicateList outerPredicateList) throws StandardException
Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map. RESOLVE - This means only pushing down single table expressions to DistinctNodes today. Once we have a better understanding of how the optimizer will work, we can push down join clauses.- Overrides:
pushExpressions
in classJoinNode
- Parameters:
outerPredicateList
- The PredicateList from the outer RS.- Throws:
StandardException
- Thrown on error
-
LOJ_reorderable
boolean LOJ_reorderable(int numTables) throws StandardException
This method recursively:- determines if this part of the query tree is a compound OJ of the shape required for reordering and if so,
- does a reordering.
OJ1 pT1T2 OJ1 pT2T3 / \ / \ / \ can / t3 t1 OJ2 pT2T3 reorder / / \ to OJ2 pT1T2 / \ / \ t2 t3 / \ t1 t2 where pR1R2 is a null-rejecting predicate which references the schema of joinee R1 and R2, cf. terminology explanation in #isNullRejecting. OJ1 represents this before and after the reordering.
The join predicates are assumed to be in CNF form. Note: Present implementation limitations- Only left outer joins are considered, i.e. both OJs in diagram above must be LOJ.
- Top left side must be a base table (t1 above). The bottow right side (t3 above) may be another OJ, so reordering can happen recursively.
- Overrides:
LOJ_reorderable
in classJoinNode
- Parameters:
numTables
- number of tables involved (needed to right size the bitmaps)- Returns:
- boolean true if any reordering took place at this level or deeper so caller can know whether rebinding may be necessary
- Throws:
StandardException
- standard error policy
-
isNullRejecting
private boolean isNullRejecting(ValueNode joinClause, JBitSet leftTableMap, JBitSet rightTableMap) throws StandardException
Tests pRiRj in the sense of Galindo-Legaria et al: Outerjoin Simplification and Reordering for Query Optimization, ACM Transactions on Database Systems, Vol. 22, No. 1, March 1997, Pages 43-74:"The set of attributes referenced by a predicate p is called the schema of p, and denoted sch(p). As a notational convention, we annotate predicates to reflect their schema. If sch(p) includes attributes of both Ri, Rj and only those relations, we can write the predicate as pRiRj.
If a null-valued column is compared in a predicate that contains no OR connectives, the predicate evaluates to undefined, and the tuple is rejected. The relops satisfy this criterion. To simplify analysis, we only accept predicates of the form:X relop Y [and .. and X-n relop Y-n]
At least one of the relops should reference bothleftTableMap
andrightTableMap
, so that we know that sch(p) includes attributes of both Ri, Rj. I.e.X
should be a table inleftTableMap
, andY
should be a table inrightTableMap
. orX
should be a table inrightTableMap
, andY
should be a table inleftTableMap
.- Parameters:
joinClause
- The join clause (i.e. predicate) we want to checkleftTableMap
- a bit map representing the tables expected for the predicate (logical left)rightTableMap
- a bit map representing the tables expected for the predicate (logical right)- Returns:
- true if the
joinClause
has at least one relop that references bothleftTableMap
andrightTableMap
- Throws:
StandardException
- standard exception policy
-
LOJ_bindResultColumns
boolean LOJ_bindResultColumns(boolean anyChange) throws StandardException
- Throws:
StandardException
-
transformOuterJoins
FromTable transformOuterJoins(ValueNode predicateTree, int numTables) throws StandardException
Transform any Outer Join into an Inner Join where applicable. (Based on the existence of a null intolerant predicate on the inner table.)- Overrides:
transformOuterJoins
in classJoinNode
- Parameters:
predicateTree
- The predicate tree for the query block- Returns:
- The new tree top (OuterJoin or InnerJoin).
- Throws:
StandardException
- Thrown on error
-
adjustNumberOfRowsReturned
protected void adjustNumberOfRowsReturned(CostEstimate costEstimate)
Description copied from class:JoinNode
Some types of joins (e.g. outer joins) will return a different number of rows than is predicted by optimizeIt() in JoinNode. So, adjust this value now. This method does nothing for most join types.- Overrides:
adjustNumberOfRowsReturned
in classJoinNode
- See Also:
JoinNode.adjustNumberOfRowsReturned(org.apache.derby.iapi.sql.compile.CostEstimate)
-
generate
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
Generate the code for an inner join node.- Overrides:
generate
in classJoinNode
- Parameters:
acb
- The ActivationClassBuilder for the class being builtmb
- The method for the generated code to go into- Throws:
StandardException
- Thrown on error
-
addOuterJoinArguments
int addOuterJoinArguments(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
Generate and add any arguments specifict to outer joins. Generate the methods (and add them as parameters) for returning an empty row from 1 or more sides of an outer join, if required. Pass whether or not this was originally a right outer join.- Overrides:
addOuterJoinArguments
in classJoinNode
- Parameters:
acb
- The ActivationClassBuildermb
- the method the generate code is to go into return The args that have been added- Throws:
StandardException
- Thrown on error
-
getNumJoinArguments
protected int getNumJoinArguments()
Return the number of arguments to the join result set.- Overrides:
getNumJoinArguments
in classJoinNode
-
oneRowRightSide
void oneRowRightSide(ActivationClassBuilder acb, MethodBuilder mb)
- Overrides:
oneRowRightSide
in classJoinNode
-
getLogicalLeftResultSet
ResultSetNode getLogicalLeftResultSet()
Return the logical left result set for this qualified join node. (For RIGHT OUTER JOIN, the left is the right and the right is the left and the JOIN is the NIOJ).- Overrides:
getLogicalLeftResultSet
in classJoinNode
-
getLogicalRightResultSet
ResultSetNode getLogicalRightResultSet()
Return the logical right result set for this qualified join node. (For RIGHT OUTER JOIN, the left is the right and the right is the left and the JOIN is the NIOJ).- Overrides:
getLogicalRightResultSet
in classJoinNode
-
isRightOuterJoin
boolean isRightOuterJoin()
Return true if right outer join or false if left outer join Used to set Nullability correctly in JoinNode
-
isJoinColumnForRightOuterJoin
void isJoinColumnForRightOuterJoin(ResultColumn rc)
If this is a right outer join node with USING/NATURAL clause, then check if the passed ResultColumn is a join column. If yes, then ResultColumn should be marked such. DERBY-4631- Overrides:
isJoinColumnForRightOuterJoin
in classFromTable
- See Also:
isJoinColumnForRightOuterJoin(org.apache.derby.impl.sql.compile.ResultColumn)
-
LOJgetNPReferencedTables
JBitSet LOJgetNPReferencedTables(int numTables) throws StandardException
- Throws:
StandardException
-
LOJgetRPReferencedTables
public JBitSet LOJgetRPReferencedTables(int numTables) throws StandardException
- Throws:
StandardException
-
-