Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class JoinNode

extends TableOperatorNode
Class Inheritance
Known Direct Subclasses
org.apache.derby.impl.sql.compile.HalfOuterJoinNode
Imports
java.util.ArrayList, .List, .Properties, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, .SQLState, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.CompilerContext, .CostEstimate, .Optimizable, .OptimizablePredicate, .OptimizablePredicateList, .Optimizer, .RowOrdering, .Visitor, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, .TableDescriptor, org.apache.derby.iapi.store.access.TransactionController, org.apache.derby.iapi.types.DataTypeDescriptor, .TypeId, org.apache.derby.iapi.util.JBitSet, .PropertyUtil

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.

Field Summary

Modifier and TypeField and Description
pack-priv List<AggregateNode>
pack-priv static final int
protected boolean
pack-priv static final int
pack-priv static final int
pack-priv ValueNode
pack-priv boolean
pack-priv Properties
pack-priv PredicateList
pack-priv static final int
private PredicateList
private boolean
naturalJoin

If this flag is true, this node represents a natural join.

private boolean
pack-priv static final int
private PredicateList
pack-priv SubqueryList
pack-priv static final int
pack-priv ResultColumnList
Inherited from org.apache.derby.impl.sql.compile.TableOperatorNode:
leftOptimizerleftResultSetrightOptimizerrightResultSet

Constructor Summary

AccessConstructor and Description
pack-priv
JoinNode(ResultSetNode
The ResultSetNode on the left side of this join
leftResult
,
ResultSetNode
The ResultSetNode on the right side of this join
rightResult
,
ValueNode
The ON clause
onClause
,
ResultColumnList
The USING clause
usingClause
,
ResultColumnList
The result column list for the join
selectList
,
Properties
Properties list associated with the table
tableProperties
,
Properties
User provided optimizer overrides
joinOrderStrategyProperties
,
ContextManager
The context manager
cm
)

Constructor for a JoinNode.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.acceptChildren.

Accept the visitor for all visitable children of this node.

pack-priv int
addOuterJoinArguments(ActivationClassBuilder
The ActivationClassBuilder
acb
,
MethodBuilder
the method the generated code is to go into return The number of args added
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.

public ValueNode

Returns:

the bound expression
bindExpression
(ValueNode expression, boolean useLeftChild, boolean useRightChild, String expressionType)

Bind an expression against the child tables of the JoinNode.

public void
bindExpressions(FromList
FromList to use/append to.
fromListParam
)

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.bindExpressions.

Bind the expressions under this node.

pack-priv void
bindResultColumns(FromList
FromList to use/append to.
fromListParam
)

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.bindResultColumns.

Bind the result columns of this ResultSetNode when there is no base table to bind them to.

pack-priv void
bindResultColumns(TableDescriptor
The TableDescriptor for the table being updated or inserted into
targetTableDescriptor
,
FromVTI targetVTI, ResultColumnList
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.
targetColumnList
,
DMLStatementNode
Calling DMLStatementNode (Insert or Update)
statement
,
FromList
FromList to use/append to.
fromListParam
)

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.bindResultColumns.

Bind the result columns for this ResultSetNode to a base table.

private void
buildRCL()

Build the RCL for this node.

private void
private static List<String>

Returns:

a list of all the column names in the RCL
extractColumnNames
(ResultColumnList
the result column list to extract the names from
rcl
)

Extract all the column names from a result column list.

pack-priv FromList

Returns:

FromList The fromList from the underlying SelectNode.
flatten
(ResultColumnList
The RCL from the outer query
rcl
,
PredicateList
PredicateList to append wherePredicates to.
outerPList
,
SubqueryList
The SubqueryList from the outer query
sql
,
GroupByList
The group by list, if any
gbl
,
ValueNode
The HAVING clause, if any
havingClause
)

Overrides org.apache.derby.impl.sql.compile.FromTable.flatten.

Flatten this JoinNode into the outer query block.

pack-priv void
generate(ActivationClassBuilder
The ActivationClassBuilder for the class being built
acb
,
MethodBuilder
The method for the generated code to go into
mb
)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.generate.

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

pack-priv void
generateCore(ActivationClassBuilder acb, MethodBuilder mb, int joinType)

Generate the code for a qualified join node.

pack-priv void
generateCore(ActivationClassBuilder
The ActivationClassBuilder
acb
,
MethodBuilder
the method the code is to go into
mb
,
int
The join type
joinType
,
ValueNode
The join clause, if any
joinClause
,
SubqueryList
The list of subqueries in the join clause, if any
subquerys
)

Do the generation work for the join node hierarchy.

pack-priv ResultColumnList

Returns:

ResultColumnList List of result columns from this table.
getAllResultColumns
(TableName
The qualifier on the "*"
allTableName
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getAllResultColumns.

Return a ResultColumnList with all of the columns in this table.

private ResultColumnList

Returns:

ResultColumnList List of result columns from this table.
getAllResultColumnsNoUsing
(TableName
The qualifier on the "*"
allTableName
)

Return a ResultColumnList with all of the columns in this table.

private ResultColumnList

Returns:

RCL with all the common columns
getCommonColumnsForNaturalJoin
()

Generate a result column list with all the column names that appear on both sides of the join operator.

pack-priv CostEstimate

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.
getFinalCostEstimate
()

Overrides org.apache.derby.impl.sql.compile.FromTable.getFinalCostEstimate.

Get the final CostEstimate for this FromTable.

private int

Returns:

The array of arguments to the join result set
getJoinArguments
(ActivationClassBuilder
The ActivationClassBuilder for the class we're building.
acb
,
MethodBuilder
the method the generated code is going into
mb
,
ValueNode
The join clause, if any
joinClause
)

Get the arguments to the join result set.

protected PredicateList
pack-priv ResultSetNode
getLogicalLeftResultSet()

Return the logical left result set for this qualified join node.

pack-priv ResultSetNode
getLogicalRightResultSet()

Return the logical right result set for this qualified join node.

pack-priv ResultColumn

Returns:

A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
getMatchingColumn
(ColumnReference
The columnReference whose name we're looking for in the given table.
columnReference
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getMatchingColumn.

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
private void
grabJoinPredicates(PredicateList outerPredicateList)

pack-priv boolean

Returns:

boolean Whether or not this FromTable can be flattened.
isFlattenableJoinNode
()

Overrides org.apache.derby.impl.sql.compile.FromTable.isFlattenableJoinNode.

Is this FromTable a JoinNode which can be flattened into the parents FromList.

pack-priv boolean

Returns:

Whether the underlying ResultSet tree is ordered on the specified column.
isOrderedOn
(ColumnReference[]
The specified ColumnReference[]
crs
,
boolean
Whether or not the order of the CRs in the array can be permuted
permuteOrdering
,
List<FromBaseTable>
List that is to be filled with the FromBaseTable
fbtHolder
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.isOrderedOn.

Return whether or not the underlying ResultSet tree is ordered on the specified columns.

pack-priv static String

Returns:

String The joinType as a String.
joinTypeToString
(int
The joinType as an int.
joinType
)

Convert the joinType to a string.

pack-priv boolean
LOJ_reorderable(int numTables)

Overrides org.apache.derby.impl.sql.compile.FromTable.LOJ_reorderable.

Currently we don't reordering any outer join w/ inner joins.

pack-priv JBitSet
public FromList
makeFromList(boolean useLeftChild, boolean useRightChild)

Make a FromList for binding

public Optimizable
modifyAccessPath(JBitSet
Bit map of the tables that are outer to this one in the join order.
outerTables
)

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.modifyAccessPath.

Implements org.apache.derby.iapi.sql.compile.Optimizable.modifyAccessPath.

Modify the access path for this Optimizable, as necessary.

pack-priv void
normExpressions()

Put the expression trees in conjunctive normal form

pack-priv void
notFlattenableJoin()

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.notFlattenableJoin.

Mark this node and its children as not being a flattenable join.

pack-priv void
public CostEstimate
optimizeIt(Optimizer
Optimizer to use.
optimizer
,
OptimizablePredicateList
The predicate list to optimize against
predList
,
CostEstimate
The CostEstimate for the outer tables in the join order, telling how many times this Optimizable will be scanned.
outerCost
,
RowOrdering
The row ordering for all the tables in the join order, including this one.
rowOrdering
)

Overrides org.apache.derby.impl.sql.compile.FromTable.optimizeIt.

Implements org.apache.derby.iapi.sql.compile.Optimizable.optimizeIt.

Choose the best access path for this Optimizable.

pack-priv ResultSetNode

Returns:

The generated ProjectRestrictNode atop the original FromTable.
preprocess
(int
Number of tables in the DML Statement
numTables
,
GroupByList
The group by list, if any
gbl
,
FromList
The from list, if any
fromList
)

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.preprocess.

Put a ProjectRestrictNode on top of each FromTable in the FromList.

pack-priv void
printSubNodes(int
The depth of this node in the tree
depth
)

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.printSubNodes.

Prints the sub-nodes of this object.

pack-priv void
projectResultColumns()

Overrides org.apache.derby.impl.sql.compile.TableOperatorNode.projectResultColumns.

Find the unreferenced result columns and project them out.

pack-priv void
pushExpressions(PredicateList
The PredicateList from the outer RS.
outerPredicateList
)

Overrides org.apache.derby.impl.sql.compile.FromTable.pushExpressions.

Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map.

protected void
private void
public boolean
pushOptPredicate(OptimizablePredicate
OptimizablePredicate to push down.
optimizablePredicate
)

Overrides org.apache.derby.impl.sql.compile.FromTable.pushOptPredicate.

Implements org.apache.derby.iapi.sql.compile.Optimizable.pushOptPredicate.

Push an OptimizablePredicate down, if this node accepts it.

pack-priv void
pack-priv void
setNaturalJoin()

Flag this as a natural join so that an implicit USING clause will be generated in the bind phase.

pack-priv void
pack-priv FromTable

Returns:

The new tree top (OuterJoin or InnerJoin).
transformOuterJoins
(ValueNode
The predicate tree for the query block
predicateTree
,
int numTables)

Overrides org.apache.derby.impl.sql.compile.FromTable.transformOuterJoins.

Transform any Outer Join into an Inner Join where applicable.

pack-priv int

Returns:

The lock mode
updateTargetLockMode
()

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.updateTargetLockMode.

Get the lock mode for the target of an update statement (a delete or update).

Inherited from org.apache.derby.impl.sql.compile.TableOperatorNode:
adjustForSortEliminationadjustForSortEliminationbindExpressionsWithTablesbindNonVTITablesbindUntypedNullsToResultColumnsbindVTITablesdecrementLevelgetExposedNamegetFromTableByNamegetLeftmostResultSetgetLeftResultSetgetRightResultSetmodifyAccessPathsneedsSpecialRCLBindingoptimizeoptimizeSourcereferencesSessionSchemareferencesTargetrejectParameterssetLeftmostResultSetsetLevelsetNestedInParenssetReferencedColumnstoStringupdateBestPlanMapverifyProperties