Class JoinNode
- java.lang.Object
-
- All Implemented Interfaces:
Optimizable
,Visitable
- Direct Known Subclasses:
HalfOuterJoinNode
class JoinNode extends TableOperatorNode
A JoinNode represents a join result set for either of the basic DML operations: SELECT and INSERT. For INSERT - SELECT, any of the fields in a JoinNode can be used (the JoinNode represents the (join) SELECT statement in the INSERT - SELECT). For INSERT, the resultColumns in the selectList will contain the names of the columns being inserted into or updated.
-
-
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 (package private) java.util.List<AggregateNode>
aggregates
(package private) static int
CROSSJOIN
protected boolean
flattenableJoin
(package private) static int
FULLOUTERJOIN
(package private) static int
INNERJOIN
(package private) ValueNode
joinClause
(package private) boolean
joinClauseNormalized
(package private) java.util.Properties
joinOrderStrategyProperties
(package private) PredicateList
joinPredicates
(package private) static int
LEFTOUTERJOIN
private PredicateList
leftPredicateList
private boolean
naturalJoin
If this flag is true, this node represents a natural join.private boolean
optimized
(package private) static int
RIGHTOUTERJOIN
private PredicateList
rightPredicateList
(package private) SubqueryList
subqueryList
(package private) static int
UNIONJOIN
(package private) ResultColumnList
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 JoinNode(ResultSetNode leftResult, ResultSetNode rightResult, ValueNode onClause, ResultColumnList usingClause, ResultColumnList selectList, java.util.Properties tableProperties, java.util.Properties joinOrderStrategyProperties, ContextManager cm)
Constructor for a JoinNode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
acceptChildren(Visitor v)
Accept the visitor for all visitable children of this node.(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.ValueNode
bindExpression(ValueNode expression, boolean useLeftChild, boolean useRightChild, java.lang.String expressionType)
Bind an expression against the child tables of the JoinNode.void
bindExpressions(FromList fromListParam)
Bind the expressions under this node.(package private) void
bindResultColumns(TableDescriptor targetTableDescriptor, FromVTI targetVTI, ResultColumnList targetColumnList, DMLStatementNode statement, FromList fromListParam)
Bind the result columns for this ResultSetNode to a base table.(package private) void
bindResultColumns(FromList fromListParam)
Bind the result columns of this ResultSetNode when there is no base table to bind them to.private void
buildRCL()
Build the RCL for this node.private void
deferredBindExpressions(FromList fromListParam)
private static java.util.List<java.lang.String>
extractColumnNames(ResultColumnList rcl)
Extract all the column names from a result column list.(package private) FromList
flatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause)
Flatten this JoinNode into the outer query block.(package private) void
generate(ActivationClassBuilder acb, MethodBuilder mb)
For joins, the tree will be (nodes are left out if the clauses are empty): ProjectRestrictResultSet -- for the having and the select list SortResultSet -- for the group by list ProjectRestrictResultSet -- for the where and the select list (if no group or having) the result set for the fromList(package private) void
generateCore(ActivationClassBuilder acb, MethodBuilder mb, int joinType)
Generate the code for a qualified join node.(package private) void
generateCore(ActivationClassBuilder acb, MethodBuilder mb, int joinType, ValueNode joinClause, SubqueryList subquerys)
Do the generation work for the join node hierarchy.(package private) ResultColumnList
getAllResultColumns(TableName allTableName)
Return a ResultColumnList with all of the columns in this table.private ResultColumnList
getAllResultColumnsNoUsing(TableName allTableName)
Return a ResultColumnList with all of the columns in this table.private ResultColumnList
getCommonColumnsForNaturalJoin()
Generate a result column list with all the column names that appear on both sides of the join operator.(package private) CostEstimate
getFinalCostEstimate()
Get the final CostEstimate for this FromTable.private int
getJoinArguments(ActivationClassBuilder acb, MethodBuilder mb, ValueNode joinClause)
Get the arguments to the join result set.protected PredicateList
getLeftPredicateList()
(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.(package private) ResultColumn
getMatchingColumn(ColumnReference columnReference)
Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.protected int
getNumJoinArguments()
Return the number of arguments to the join result set.protected PredicateList
getRightPredicateList()
private void
grabJoinPredicates(PredicateList outerPredicateList)
(package private) boolean
isFlattenableJoinNode()
Is this FromTable a JoinNode which can be flattened into the parents FromList.(package private) boolean
isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, java.util.List<FromBaseTable> fbtHolder)
Return whether or not the underlying ResultSet tree is ordered on the specified columns.(package private) static java.lang.String
joinTypeToString(int joinType)
Convert the joinType to a string.(package private) boolean
LOJ_reorderable(int numTables)
Currently we don't reordering any outer join w/ inner joins.(package private) JBitSet
LOJgetReferencedTables(int numTables)
FromList
makeFromList(boolean useLeftChild, boolean useRightChild)
Make a FromList for bindingOptimizable
modifyAccessPath(JBitSet outerTables)
Modify the access path for this Optimizable, as necessary.(package private) void
normExpressions()
Put the expression trees in conjunctive normal form(package private) void
notFlattenableJoin()
Mark this node and its children as not being a flattenable join.(package private) void
oneRowRightSide(ActivationClassBuilder acb, MethodBuilder mb)
CostEstimate
optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering)
Choose the best access path for this Optimizable.(package private) ResultSetNode
preprocess(int numTables, GroupByList gbl, FromList fromList)
Put a ProjectRestrictNode on top of each FromTable in the FromList.(package private) void
printSubNodes(int depth)
Prints the sub-nodes of this object.(package private) void
projectResultColumns()
Find the unreferenced result columns and project them out.(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.protected void
pushExpressionsToLeft(PredicateList outerPredicateList)
private void
pushExpressionsToRight(PredicateList outerPredicateList)
boolean
pushOptPredicate(OptimizablePredicate optimizablePredicate)
Push an OptimizablePredicate down, if this node accepts it.(package private) void
setAggregates(java.util.List<AggregateNode> aggregates)
(package private) void
setNaturalJoin()
Flag this as a natural join so that an implicit USING clause will be generated in the bind phase.(package private) void
setSubqueryList(SubqueryList subqueryList)
(package private) FromTable
transformOuterJoins(ValueNode predicateTree, int numTables)
Transform any Outer Join into an Inner Join where applicable.(package private) int
updateTargetLockMode()
Get the lock mode for the target of an update statement (a delete or update).-
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, toString, 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, isJoinColumnForRightOuterJoin, 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
-
-
-
-
Field Detail
-
INNERJOIN
static final int INNERJOIN
- See Also:
- Constant Field Values
-
CROSSJOIN
static final int CROSSJOIN
- See Also:
- Constant Field Values
-
LEFTOUTERJOIN
static final int LEFTOUTERJOIN
- See Also:
- Constant Field Values
-
RIGHTOUTERJOIN
static final int RIGHTOUTERJOIN
- See Also:
- Constant Field Values
-
FULLOUTERJOIN
static final int FULLOUTERJOIN
- See Also:
- Constant Field Values
-
UNIONJOIN
static final int UNIONJOIN
- See Also:
- Constant Field Values
-
naturalJoin
private boolean naturalJoin
If this flag is true, this node represents a natural join.
-
optimized
private boolean optimized
-
leftPredicateList
private PredicateList leftPredicateList
-
rightPredicateList
private PredicateList rightPredicateList
-
flattenableJoin
protected boolean flattenableJoin
-
aggregates
java.util.List<AggregateNode> aggregates
-
subqueryList
SubqueryList subqueryList
-
joinClause
ValueNode joinClause
-
joinClauseNormalized
boolean joinClauseNormalized
-
joinPredicates
PredicateList joinPredicates
-
usingClause
ResultColumnList usingClause
-
joinOrderStrategyProperties
java.util.Properties joinOrderStrategyProperties
-
-
Constructor Detail
-
JoinNode
JoinNode(ResultSetNode leftResult, ResultSetNode rightResult, ValueNode onClause, ResultColumnList usingClause, ResultColumnList selectList, java.util.Properties tableProperties, java.util.Properties joinOrderStrategyProperties, ContextManager cm) throws StandardException
Constructor for a JoinNode.- 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 clauseselectList
- The result column list for the jointableProperties
- Properties list associated with the tablejoinOrderStrategyProperties
- User provided optimizer overridescm
- The context manager- Throws:
StandardException
- Thrown on error
-
-
Method Detail
-
optimizeIt
public CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering) throws StandardException
Description copied from interface:Optimizable
Choose the best access path for this Optimizable.- Specified by:
optimizeIt
in interfaceOptimizable
- Overrides:
optimizeIt
in classFromTable
- Parameters:
optimizer
- Optimizer to use.predList
- The predicate list to optimize againstouterCost
- The CostEstimate for the outer tables in the join order, telling how many times this Optimizable will be scanned.rowOrdering
- The row ordering for all the tables in the join order, including this one.- Returns:
- The optimizer's estimated cost of the best access path.
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.optimizeIt(org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.CostEstimate, org.apache.derby.iapi.sql.compile.RowOrdering)
-
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 classFromTable
- 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)
-
modifyAccessPath
public Optimizable modifyAccessPath(JBitSet outerTables) throws StandardException
Description copied from interface:Optimizable
Modify the access path for this Optimizable, as necessary. This includes things like adding a result set to translate from index rows to base rows- Specified by:
modifyAccessPath
in interfaceOptimizable
- Overrides:
modifyAccessPath
in classTableOperatorNode
- Parameters:
outerTables
- Bit map of the tables that are outer to this one in the join order.- Returns:
- The (potentially new) Optimizable at the top of the tree.
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.modifyAccessPath(org.apache.derby.iapi.util.JBitSet)
-
adjustNumberOfRowsReturned
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. So, adjust this value now. This method does nothing for most join types.
-
getAllResultColumns
ResultColumnList getAllResultColumns(TableName allTableName) throws StandardException
Return a ResultColumnList with all of the columns in this table. (Used in expanding '*'s.) NOTE: Since this method is for expanding a "*" in the SELECT list, ResultColumn.expression will be a ColumnReference.- Overrides:
getAllResultColumns
in classResultSetNode
- Parameters:
allTableName
- The qualifier on the "*"- Returns:
- ResultColumnList List of result columns from this table.
- Throws:
StandardException
- Thrown on error
-
getAllResultColumnsNoUsing
private ResultColumnList getAllResultColumnsNoUsing(TableName allTableName) throws StandardException
Return a ResultColumnList with all of the columns in this table. (Used in expanding '*'s.) NOTE: Since this method is for expanding a "*" in the SELECT list, ResultColumn.expression will be a ColumnReference. NOTE: This method is handles the case when there is no USING clause. The caller handles the case when there is a USING clause.- Parameters:
allTableName
- The qualifier on the "*"- Returns:
- ResultColumnList List of result columns from this table.
- Throws:
StandardException
- Thrown on error
-
getMatchingColumn
ResultColumn getMatchingColumn(ColumnReference columnReference) throws StandardException
Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.- Overrides:
getMatchingColumn
in classResultSetNode
- Parameters:
columnReference
- The columnReference whose name we're looking for in the given table.- Returns:
- A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
- Throws:
StandardException
- Thrown on error
-
bindExpressions
public void bindExpressions(FromList fromListParam) throws StandardException
Bind the expressions under this node.- Overrides:
bindExpressions
in classTableOperatorNode
- Parameters:
fromListParam
- FromList to use/append to.- Throws:
StandardException
- Thrown on error
-
bindResultColumns
void bindResultColumns(FromList fromListParam) throws StandardException
Bind the result columns of this ResultSetNode 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.- Overrides:
bindResultColumns
in classTableOperatorNode
- Parameters:
fromListParam
- FromList to use/append to.- Throws:
StandardException
- Thrown on error
-
bindResultColumns
void bindResultColumns(TableDescriptor targetTableDescriptor, FromVTI targetVTI, ResultColumnList targetColumnList, DMLStatementNode statement, FromList fromListParam) throws StandardException
Bind the result columns for this ResultSetNode to a base table. This is useful for INSERT and UPDATE statements, where the result columns get their types from the table being updated or inserted into. If a result column list is specified, then the verification that the result column list does not contain any duplicates will be done when binding them by name.- Overrides:
bindResultColumns
in classTableOperatorNode
- Parameters:
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.- Throws:
StandardException
- Thrown on error
-
buildRCL
private void buildRCL() throws StandardException
Build the RCL for this node. We propagate the RCLs up from the children and splice them to form this node's RCL.- Throws:
StandardException
- Thrown on error
-
deferredBindExpressions
private void deferredBindExpressions(FromList fromListParam) throws StandardException
- Throws:
StandardException
-
bindExpression
public ValueNode bindExpression(ValueNode expression, boolean useLeftChild, boolean useRightChild, java.lang.String expressionType) throws StandardException
Bind an expression against the child tables of the JoinNode. May update the subquery and aggregate lists in the JoinNode. Assumes that the subquery and aggregate lists for the JoinNode have already been created.- Returns:
- the bound expression
- Throws:
StandardException
-
makeFromList
public FromList makeFromList(boolean useLeftChild, boolean useRightChild) throws StandardException
Make a FromList for binding- Throws:
StandardException
-
getCommonColumnsForNaturalJoin
private ResultColumnList getCommonColumnsForNaturalJoin() throws StandardException
Generate a result column list with all the column names that appear on both sides of the join operator. Those are the columns to use as join columns in a natural join.- Returns:
- RCL with all the common columns
- Throws:
StandardException
- on error
-
extractColumnNames
private static java.util.List<java.lang.String> extractColumnNames(ResultColumnList rcl)
Extract all the column names from a result column list.- Parameters:
rcl
- the result column list to extract the names from- Returns:
- a list of all the column names in the RCL
-
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 classTableOperatorNode
- 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
-
projectResultColumns
void projectResultColumns() throws StandardException
Find the unreferenced result columns and project them out. This is used in pre-processing joins that are not flattened into the where clause.- Overrides:
projectResultColumns
in classTableOperatorNode
- Throws:
StandardException
-
normExpressions
void normExpressions() throws StandardException
Put the expression trees in conjunctive normal form- 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 classFromTable
- Parameters:
outerPredicateList
- The PredicateList from the outer RS.- Throws:
StandardException
- Thrown on error
-
pushExpressionsToLeft
protected void pushExpressionsToLeft(PredicateList outerPredicateList) throws StandardException
- Throws:
StandardException
-
pushExpressionsToRight
private void pushExpressionsToRight(PredicateList outerPredicateList) throws StandardException
- Throws:
StandardException
-
grabJoinPredicates
private void grabJoinPredicates(PredicateList outerPredicateList) throws StandardException
- Throws:
StandardException
-
flatten
FromList flatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause) throws StandardException
Flatten this JoinNode into the outer query block. The steps in flattening are: o Mark all ResultColumns as redundant, so that they are "skipped over" at generate(). o Append the joinPredicates to the outer list. o Create a FromList from the tables being joined and return that list so that the caller will merge the 2 lists- Overrides:
flatten
in classFromTable
- Parameters:
rcl
- The RCL from the outer queryouterPList
- PredicateList to append wherePredicates to.sql
- The SubqueryList from the outer querygbl
- The group by list, if anyhavingClause
- The HAVING clause, if any- Returns:
- FromList The fromList from the underlying SelectNode.
- Throws:
StandardException
- Thrown on error
-
LOJ_reorderable
boolean LOJ_reorderable(int numTables) throws StandardException
Currently we don't reordering any outer join w/ inner joins.- Overrides:
LOJ_reorderable
in classFromTable
- 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 classFromTable
- Parameters:
predicateTree
- The predicate tree for the query block- Returns:
- The new tree top (OuterJoin or InnerJoin).
- Throws:
StandardException
- Thrown on error
-
generate
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
For joins, the tree will be (nodes are left out if the clauses are empty): ProjectRestrictResultSet -- for the having and the select list SortResultSet -- for the group by list ProjectRestrictResultSet -- for the where and the select list (if no group or having) the result set for the fromList- Overrides:
generate
in classQueryTreeNode
- Parameters:
acb
- The ActivationClassBuilder for the class being builtmb
- The method for the generated code to go into- Throws:
StandardException
- Thrown on error
-
generateCore
void generateCore(ActivationClassBuilder acb, MethodBuilder mb, int joinType) throws StandardException
Generate the code for a qualified join node.- Throws:
StandardException
- Thrown on error
-
generateCore
void generateCore(ActivationClassBuilder acb, MethodBuilder mb, int joinType, ValueNode joinClause, SubqueryList subquerys) throws StandardException
Do the generation work for the join node hierarchy.- Parameters:
acb
- The ActivationClassBuildermb
- the method the code is to go intojoinType
- The join typejoinClause
- The join clause, if anysubquerys
- The list of subqueries in the join clause, if any- Throws:
StandardException
- Thrown on error
-
getJoinArguments
private int getJoinArguments(ActivationClassBuilder acb, MethodBuilder mb, ValueNode joinClause) throws StandardException
Get the arguments to the join result set.- Parameters:
acb
- The ActivationClassBuilder for the class we're building.mb
- the method the generated code is going intojoinClause
- The join clause, if any- Returns:
- The array of arguments to the join result set
- Throws:
StandardException
- Thrown on error
-
getFinalCostEstimate
CostEstimate getFinalCostEstimate() throws StandardException
Description copied from class:FromTable
Get the final CostEstimate for this FromTable.- Overrides:
getFinalCostEstimate
in classFromTable
- Returns:
- The final CostEstimate for this JoinNode, which is sum the costs for the inner and outer table. The number of rows, though, is that for the inner table only.
- Throws:
StandardException
- See Also:
Get the final CostEstimate for this JoinNode.
-
oneRowRightSide
void oneRowRightSide(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
- Throws:
StandardException
-
getNumJoinArguments
protected int getNumJoinArguments()
Return the number of arguments to the join result set. This will be overridden for other types of joins (for example, outer joins).
-
addOuterJoinArguments
int addOuterJoinArguments(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
Generate and add any arguments specifict to outer joins. (Expected to be overriden, where appropriate, in subclasses.)- Parameters:
acb
- The ActivationClassBuildermb
- the method the generated code is to go into return The number of args added- Throws:
StandardException
- Thrown on error
-
joinTypeToString
static java.lang.String joinTypeToString(int joinType)
Convert the joinType to a string.- Parameters:
joinType
- The joinType as an int.- Returns:
- String The joinType as a String.
-
getLeftPredicateList
protected PredicateList getLeftPredicateList() throws StandardException
- Throws:
StandardException
-
getRightPredicateList
protected PredicateList getRightPredicateList() throws StandardException
- Throws:
StandardException
-
updateTargetLockMode
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.- Overrides:
updateTargetLockMode
in classResultSetNode
- Returns:
- The lock mode
- See Also:
TransactionController
-
notFlattenableJoin
void notFlattenableJoin()
Mark this node and its children as not being a flattenable join.- Overrides:
notFlattenableJoin
in classResultSetNode
-
isFlattenableJoinNode
boolean isFlattenableJoinNode()
Is this FromTable a JoinNode which can be flattened into the parents FromList.- Overrides:
isFlattenableJoinNode
in classFromTable
- Returns:
- boolean Whether or not this FromTable can be flattened.
-
isOrderedOn
boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, java.util.List<FromBaseTable> fbtHolder) throws StandardException
Return whether or not the underlying ResultSet tree is ordered on the specified columns. RESOLVE - This method currently only considers the outermost table of the query block.- Overrides:
isOrderedOn
in classResultSetNode
- Parameters:
crs
- The specified ColumnReference[]permuteOrdering
- Whether or not the order of the CRs in the array can be permutedfbtHolder
- List that is to be filled with the FromBaseTable- Returns:
- Whether the underlying ResultSet tree is ordered on the specified column.
- Throws:
StandardException
- Thrown on error
-
printSubNodes
void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.- Overrides:
printSubNodes
in classTableOperatorNode
- Parameters:
depth
- The depth of this node in the tree
-
setSubqueryList
void setSubqueryList(SubqueryList subqueryList)
-
setAggregates
void setAggregates(java.util.List<AggregateNode> aggregates)
-
setNaturalJoin
void setNaturalJoin()
Flag this as a natural join so that an implicit USING clause will be generated in the bind phase.
-
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).
-
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).
-
acceptChildren
void acceptChildren(Visitor v) throws StandardException
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classTableOperatorNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-
LOJgetReferencedTables
JBitSet LOJgetReferencedTables(int numTables) throws StandardException
- Overrides:
LOJgetReferencedTables
in classResultSetNode
- Throws:
StandardException
-
-