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

pack-priv Class HalfOuterJoinNode

extends JoinNode
Class Inheritance
Imports
java.util.Properties, org.apache.derby.shared.common.error.StandardException, 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.CostEstimate, .Optimizable, .OptimizablePredicate, org.apache.derby.iapi.util.JBitSet

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.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
Inherited from org.apache.derby.impl.sql.compile.JoinNode:
aggregatesCROSSJOINflattenableJoinFULLOUTERJOININNERJOINjoinClausejoinClauseNormalizedjoinOrderStrategyPropertiesjoinPredicatesLEFTOUTERJOINRIGHTOUTERJOINsubqueryListUNIONJOINusingClause

Constructor Summary

AccessConstructor and Description
pack-priv
HalfOuterJoinNode(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
,
boolean
Whether or not this node represents a user specified right outer join
rightOuterJoin
,
Properties
Properties list associated with the table
tableProperties
,
ContextManager
The context manager
cm
)

Constructor for a HalfOuterJoinNode.

Method Summary

Modifier and TypeMethod and Description
pack-priv int
addOuterJoinArguments(ActivationClassBuilder
The ActivationClassBuilder
acb
,
MethodBuilder
the method the generate code is to go into return The args that have been added
mb
)

Overrides org.apache.derby.impl.sql.compile.JoinNode.addOuterJoinArguments.

Generate and add any arguments specifict to outer joins.

protected void
adjustNumberOfRowsReturned(CostEstimate costEstimate)

Overrides org.apache.derby.impl.sql.compile.JoinNode.adjustNumberOfRowsReturned.

Some types of joins (e.g. outer joins) will return a different number of rows than is predicted by optimizeIt() in JoinNode.

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.JoinNode.generate.

Generate the code for an inner join node.

pack-priv ResultSetNode
getLogicalLeftResultSet()

Overrides org.apache.derby.impl.sql.compile.JoinNode.getLogicalLeftResultSet.

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

pack-priv ResultSetNode
getLogicalRightResultSet()

Overrides org.apache.derby.impl.sql.compile.JoinNode.getLogicalRightResultSet.

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

protected int
getNumJoinArguments()

Overrides org.apache.derby.impl.sql.compile.JoinNode.getNumJoinArguments.

Return the number of arguments to the join result set.

pack-priv void
isJoinColumnForRightOuterJoin(ResultColumn rc)

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

If this is a right outer join node with USING/NATURAL clause, then check if the passed ResultColumn is a join column.

private boolean

Returns:

true if the joinClause has at least one relop that references both leftTableMap and rightTableMap
isNullRejecting
(ValueNode
The join clause (i.e. predicate) we want to check
joinClause
,
JBitSet
a bit map representing the tables expected for the predicate (logical left)
leftTableMap
,
JBitSet
a bit map representing the tables expected for the predicate (logical right)
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.</quote>

pack-priv boolean
isRightOuterJoin()

Return true if right outer join or false if left outer join Used to set Nullability correctly in JoinNode

pack-priv boolean
LOJ_bindResultColumns(boolean anyChange)

pack-priv boolean

Returns:

boolean true if any reordering took place at this level or deeper so caller can know whether rebinding may be necessary
LOJ_reorderable
(int
number of tables involved (needed to right size the bitmaps)
numTables
)

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

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.
pack-priv JBitSet
LOJgetNPReferencedTables(int numTables)

public JBitSet
LOJgetRPReferencedTables(int numTables)

pack-priv void
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.JoinNode.preprocess.

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

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

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

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

public boolean
pushOptPredicate(OptimizablePredicate
OptimizablePredicate to push down.
optimizablePredicate
)

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

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

Push an OptimizablePredicate down, if this node accepts it.

public String

Returns:

This object as a String
toString
()

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

Convert this object to a String.

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.JoinNode.transformOuterJoins.

Transform any Outer Join into an Inner Join where applicable.

Inherited from org.apache.derby.impl.sql.compile.JoinNode:
acceptChildrenbindExpressionbindExpressionsbindResultColumnsbindResultColumnsflattengenerateCoregenerateCoregetAllResultColumnsgetFinalCostEstimategetLeftPredicateListgetMatchingColumngetRightPredicateListisFlattenableJoinNodeisOrderedOnjoinTypeToStringLOJgetReferencedTablesmakeFromListmodifyAccessPathnormExpressionsnotFlattenableJoinoptimizeItprintSubNodesprojectResultColumnspushExpressionsToLeftsetAggregatessetNaturalJoinsetSubqueryListupdateTargetLockMode

Field Detail

rightOuterJoinback to summary
private boolean rightOuterJoin
transformedback to summary
private boolean transformed

Constructor Detail

HalfOuterJoinNodeback to summary
pack-priv HalfOuterJoinNode(ResultSetNode leftResult, ResultSetNode rightResult, ValueNode onClause, ResultColumnList usingClause, boolean rightOuterJoin, Properties tableProperties, ContextManager cm) throws StandardException

Constructor for a HalfOuterJoinNode.

Parameters
leftResult:ResultSetNode

The ResultSetNode on the left side of this join

rightResult:ResultSetNode

The ResultSetNode on the right side of this join

onClause:ValueNode

The ON clause

usingClause:ResultColumnList

The USING clause

rightOuterJoin:boolean

Whether or not this node represents a user specified right outer join

tableProperties:Properties

Properties list associated with the table

cm:ContextManager

The context manager

Exceptions
StandardException:
Thrown on error

Method Detail

addOuterJoinArgumentsback to summary
pack-priv int addOuterJoinArguments(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException

Overrides org.apache.derby.impl.sql.compile.JoinNode.addOuterJoinArguments.

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.

Parameters
acb:ActivationClassBuilder

The ActivationClassBuilder

mb:MethodBuilder

the method the generate code is to go into return The args that have been added

Annotations
@Override
Exceptions
StandardException:
Thrown on error
adjustNumberOfRowsReturnedback to summary
protected void adjustNumberOfRowsReturned(CostEstimate costEstimate)

Overrides org.apache.derby.impl.sql.compile.JoinNode.adjustNumberOfRowsReturned.

Doc from org.apache.derby.impl.sql.compile.JoinNode.adjustNumberOfRowsReturned.

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.

Annotations
@Override
See Also
JoinNode#adjustNumberOfRowsReturned
generateback to summary
pack-priv void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException

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

Generate the code for an inner join node.

Parameters
acb:ActivationClassBuilder

Doc from org.apache.derby.impl.sql.compile.QueryTreeNode.generate.

The ActivationClassBuilder for the class being built

mb:MethodBuilder

Doc from org.apache.derby.impl.sql.compile.QueryTreeNode.generate.

The method for the generated code to go into

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getLogicalLeftResultSetback to summary
pack-priv ResultSetNode getLogicalLeftResultSet()

Overrides org.apache.derby.impl.sql.compile.JoinNode.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).

Annotations
@Override
getLogicalRightResultSetback to summary
pack-priv ResultSetNode getLogicalRightResultSet()

Overrides org.apache.derby.impl.sql.compile.JoinNode.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).

Annotations
@Override
getNumJoinArgumentsback to summary
protected int getNumJoinArguments()

Overrides org.apache.derby.impl.sql.compile.JoinNode.getNumJoinArguments.

Return the number of arguments to the join result set.

Annotations
@Override
isJoinColumnForRightOuterJoinback to summary
pack-priv void isJoinColumnForRightOuterJoin(ResultColumn rc)

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

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

Annotations
@Override
isNullRejectingback to summary
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 both leftTableMap and rightTableMap, so that we know that sch(p) includes attributes of both Ri, Rj. I.e.

X should be a table in leftTableMap, and Y should be a table in rightTableMap.

or X should be a table in rightTableMap, and Y should be a table in leftTableMap.

Parameters
joinClause:ValueNode

The join clause (i.e. predicate) we want to check

leftTableMap:JBitSet

a bit map representing the tables expected for the predicate (logical left)

rightTableMap:JBitSet

a bit map representing the tables expected for the predicate (logical right)

Returns:boolean

true if the joinClause has at least one relop that references both leftTableMap and rightTableMap

Exceptions
StandardException:
standard exception policy
isRightOuterJoinback to summary
pack-priv boolean isRightOuterJoin()

Return true if right outer join or false if left outer join Used to set Nullability correctly in JoinNode

LOJ_bindResultColumnsback to summary
pack-priv boolean LOJ_bindResultColumns(boolean anyChange) throws StandardException
LOJ_reorderableback to summary
pack-priv boolean LOJ_reorderable(int numTables) throws StandardException

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

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.
Parameters
numTables:int

number of tables involved (needed to right size the bitmaps)

Returns:boolean

boolean true if any reordering took place at this level or deeper so caller can know whether rebinding may be necessary

Annotations
@Override
Exceptions
StandardException:
standard error policy
LOJgetNPReferencedTablesback to summary
pack-priv JBitSet LOJgetNPReferencedTables(int numTables) throws StandardException
LOJgetRPReferencedTablesback to summary
public JBitSet LOJgetRPReferencedTables(int numTables) throws StandardException
oneRowRightSideback to summary
pack-priv void oneRowRightSide(ActivationClassBuilder acb, MethodBuilder mb)

Overrides org.apache.derby.impl.sql.compile.JoinNode.oneRowRightSide.

Annotations
@Override
preprocessback to summary
pack-priv ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException

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

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.

Parameters
numTables:int

Number of tables in the DML Statement

gbl:GroupByList

The group by list, if any

fromList:FromList

The from list, if any

Returns:ResultSetNode

The generated ProjectRestrictNode atop the original FromTable.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
pushExpressionsback to summary
pack-priv void pushExpressions(PredicateList outerPredicateList) throws StandardException

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

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.

Parameters
outerPredicateList:PredicateList

The PredicateList from the outer RS.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
pushOptPredicateback to summary
public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate) throws StandardException

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

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

Doc from org.apache.derby.iapi.sql.compile.Optimizable.pushOptPredicate.

Push an OptimizablePredicate down, if this node accepts it.

Parameters
optimizablePredicate:OptimizablePredicate

OptimizablePredicate to push down.

Returns:boolean

Whether or not the predicate was pushed down.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
See Also
Optimizable#pushOptPredicate
toStringback to summary
public String toString()

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

Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Returns:String

This object as a String

Annotations
@Override
transformOuterJoinsback to summary
pack-priv FromTable transformOuterJoins(ValueNode predicateTree, int numTables) throws StandardException

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

Transform any Outer Join into an Inner Join where applicable. (Based on the existence of a null intolerant predicate on the inner table.)

Parameters
predicateTree:ValueNode

The predicate tree for the query block

Returns:FromTable

The new tree top (OuterJoin or InnerJoin).

Annotations
@Override
Exceptions
StandardException:
Thrown on error