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

pack-priv Class UnionNode

extends SetOperatorNode
Class Inheritance
Imports
java.util.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.CostEstimate, .Optimizable, .OptimizablePredicateList, .Optimizer, .RowOrdering, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, org.apache.derby.iapi.types.DataTypeDescriptor, org.apache.derby.iapi.util.JBitSet

A UnionNode represents a UNION in a DML statement. It contains a boolean telling whether the union operation should eliminate duplicate rows.

Field Summary

Modifier and TypeField and Description
private boolean
pack-priv boolean
pack-priv boolean
Inherited from org.apache.derby.impl.sql.compile.SetOperatorNode:
allqec

Constructor Summary

AccessConstructor and Description
pack-priv
UnionNode(ResultSetNode
The ResultSetNode on the left side of this union
leftResult
,
ResultSetNode
The ResultSetNode on the right side of this union
rightResult
,
boolean
Whether or not this is a UNION ALL.
all
,
boolean
Whether or not this is from a table constructor.
tableConstructor
,
Properties
Properties list associated with the table
tableProperties
,
ContextManager cm)

Constructor for a UnionNode.

Method Summary

Modifier and TypeMethod and Description
private ResultSetNode

Returns:

(Potentially new) head of the ResultSetNode tree.
addNewNodes
()

Add any new ResultSetNodes that are necessary to the tree.

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

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

Bind the expressions under this TableOperatorNode.

pack-priv ResultSetNode
enhanceRCLForInsert(InsertNode
the target node for the insert
target
,
boolean
are source cols in same order as target cols?
inOrder
,
int[]
int array representation of correspondence between RCLs - colmap[i] = -1 -> missing in current RCL colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
colMap
)

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

Make the RCL of this node match the target node for the insert.

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.

Generate the code for this UnionNode.

pack-priv CostEstimate

Returns:

The final CostEstimate for this UnionNode, which is the sum of the two child costs.
getFinalCostEstimate
()

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

Get the final CostEstimate for this FromTable.

pack-priv String
pack-priv void
markTopTableConstructor()

Mark this as the top node of a table constructor.

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 ResultSetNode
modifyAccessPaths()

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

Modify the access paths according to the decisions the optimizer made.

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 void
pushExpressions(PredicateList
List of single table predicates to push
predicateList
)

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

DERBY-649: Handle pushing predicates into UnionNodes.

pack-priv void
pack-priv void
setTableConstructorTypes(ResultColumnList
The ResultColumnList containing the desired result types.
typeColumns
)

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

Set the type of column in the result column lists of each source of this union tree to the type in the given result column list (which represents the result columns for an insert).

pack-priv boolean
tableConstructor()

Tell whether this is a UNION for a table constructor.

public String

Returns:

This object as a String
toString
()

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

Convert this object to a String.

Inherited from org.apache.derby.impl.sql.compile.SetOperatorNode:
bindResultColumnsbindResultColumnsbindTargetExpressionsbindUntypedNullsToResultColumnsensurePredicateListflattenableInFromSubquerygetFromTableByNamegetLeftOptPredicateListgetParamColumnTypesgetRightOptPredicateListhasUnPushedPredicatesmodifyAccessPathperformMaterializationpreprocessprintSubNodespullOptPredicatespushOffsetFetchFirstpushOptPredicatepushOrderByListpushQueryExpressionSuffixreplaceOrForbidDefaultssetParamColumnTypessetResultToBooleanTrueNodeverifySelectStarSubquery

Field Detail

addNewNodesCalledback to summary
private boolean addNewNodesCalled
tableConstructorback to summary
pack-priv boolean tableConstructor
topTableConstructorback to summary
pack-priv boolean topTableConstructor

Constructor Detail

UnionNodeback to summary
pack-priv UnionNode(ResultSetNode leftResult, ResultSetNode rightResult, boolean all, boolean tableConstructor, Properties tableProperties, ContextManager cm) throws StandardException

Constructor for a UnionNode.

Parameters
leftResult:ResultSetNode

The ResultSetNode on the left side of this union

rightResult:ResultSetNode

The ResultSetNode on the right side of this union

all:boolean

Whether or not this is a UNION ALL.

tableConstructor:boolean

Whether or not this is from a table constructor.

tableProperties:Properties

Properties list associated with the table

Exceptions
StandardException:
Thrown on error

Method Detail

addNewNodesback to summary
private ResultSetNode addNewNodes() throws StandardException

Add any new ResultSetNodes that are necessary to the tree. We wait until after optimization to do this in order to make it easier on the optimizer.

Returns:ResultSetNode

(Potentially new) head of the ResultSetNode tree.

Exceptions
StandardException:
Thrown on error
bindExpressionsback to summary
public void bindExpressions(FromList fromListParam) throws StandardException

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

Bind the expressions under this TableOperatorNode. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.

Parameters
fromListParam:FromList

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.bindExpressions.

FromList to use/append to.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
enhanceRCLForInsertback to summary
pack-priv ResultSetNode enhanceRCLForInsert(InsertNode target, boolean inOrder, int[] colMap) throws StandardException

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

Make the RCL of this node match the target node for the insert. If this node represents a table constructor (a VALUES clause), we replace the RCL with an enhanced one if necessary, and recursively enhance the RCL of each child node. For table constructors, we also need to check that we don't attempt to override auto-increment columns in each child node (checking the top-level RCL isn't sufficient since a table constructor may contain the DEFAULT keyword, which makes it possible to specify a column without overriding its value). If this node represents a regular UNION, put a ProjectRestrictNode on top of this node and enhance the RCL in that node.

Parameters
target:InsertNode

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.enhanceRCLForInsert.

the target node for the insert

inOrder:boolean

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.enhanceRCLForInsert.

are source cols in same order as target cols?

colMap:int[]

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.enhanceRCLForInsert.

int array representation of correspondence between RCLs - colmap[i] = -1 -> missing in current RCL colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)

Returns:ResultSetNode

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.enhanceRCLForInsert.

a node that replaces this node and whose RCL matches the target RCL. May return this node if no changes to the RCL are needed, or if the RCL is modified in-place.

Annotations
@Override
Exceptions
StandardException:

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.enhanceRCLForInsert.

Thrown on error

generateback to summary
pack-priv void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException

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

Generate the code for this UnionNode.

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
getFinalCostEstimateback to summary
pack-priv CostEstimate getFinalCostEstimate() throws StandardException

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

Doc from org.apache.derby.impl.sql.compile.FromTable.getFinalCostEstimate.

Get the final CostEstimate for this FromTable.

Returns:CostEstimate

The final CostEstimate for this UnionNode, which is the sum of the two child costs.

Annotations
@Override
See Also
Get the final CostEstimate for this UnionNode.
getOperatorNameback to summary
pack-priv String getOperatorName()

Implements abstract org.apache.derby.impl.sql.compile.SetOperatorNode.getOperatorName.

Returns:String

Doc from org.apache.derby.impl.sql.compile.SetOperatorNode.getOperatorName.

the operator name: "UNION", "INTERSECT", or "EXCEPT"

markTopTableConstructorback to summary
pack-priv void markTopTableConstructor()

Mark this as the top node of a table constructor.

modifyAccessPathback to summary
public Optimizable modifyAccessPath(JBitSet outerTables) throws StandardException

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

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

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

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

Parameters
outerTables:JBitSet

Bit map of the tables that are outer to this one in the join order.

Returns:Optimizable

The (potentially new) Optimizable at the top of the tree.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
See Also
Optimizable#modifyAccessPath
modifyAccessPathsback to summary
pack-priv ResultSetNode modifyAccessPaths() throws StandardException

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

Doc from org.apache.derby.impl.sql.compile.ResultSetNode.modifyAccessPaths.

Modify the access paths according to the decisions the optimizer made. This can include adding project/restrict nodes, index-to-base-row nodes, etc.

Returns:ResultSetNode

The modified query tree

Annotations
@Override
Exceptions
StandardException:
Thrown on error
See Also
ResultSetNode#modifyAccessPaths
optimizeItback to summary
public CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering) throws StandardException

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

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

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

Choose the best access path for this Optimizable.

Parameters
optimizer:Optimizer

Optimizer to use.

predList:OptimizablePredicateList

The predicate list to optimize against

outerCost:CostEstimate

The CostEstimate for the outer tables in the join order, telling how many times this Optimizable will be scanned.

rowOrdering:RowOrdering

The row ordering for all the tables in the join order, including this one.

Returns:CostEstimate

The optimizer's estimated cost of the best access path.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
See Also
org.apache.derby.iapi.sql.compile.Optimizable#optimizeIt
pushExpressionsback to summary
pack-priv void pushExpressions(PredicateList predicateList) throws StandardException

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

DERBY-649: Handle pushing predicates into UnionNodes. It is possible to push single table predicates that are binaryOperations or inListOperations. Predicates of the form or IN are currently handled. Since these predicates would allow optimizer to pick available indices, pushing them provides maximum benifit. It should be possible to expand this logic to cover more cases. Even pushing expressions (like a+b = 10) into SELECTs would improve performance, even if they don't allow use of index. It would mean evaluating expressions closer to data and hence could avoid sorting or other overheads that UNION may require. Note that the predicates are not removed after pushing. This is to ensure if pushing is not possible or only partially feasible.

Parameters
predicateList:PredicateList

List of single table predicates to push

Annotations
@Override
Exceptions
StandardException:
Thrown on error
rejectParametersback to summary
pack-priv void rejectParameters() throws StandardException

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

Check for (and reject) ? parameters directly under the ResultColumns. This is done for SELECT statements. Don't reject parameters that are in a table constructor - these are allowed, as long as the table constructor is in an INSERT statement or each column of the table constructor has at least one non-? column. The latter case is checked below, in bindExpressions().

Annotations
@Override
Exceptions
StandardException:
Thrown if a ? parameter found directly under a ResultColumn
setTableConstructorTypesback to summary
pack-priv void setTableConstructorTypes(ResultColumnList typeColumns) throws StandardException

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

Set the type of column in the result column lists of each source of this union tree to the type in the given result column list (which represents the result columns for an insert). This is only for table constructors that appear in insert statements.

Parameters
typeColumns:ResultColumnList

The ResultColumnList containing the desired result types.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
tableConstructorback to summary
pack-priv boolean tableConstructor()

Tell whether this is a UNION for a table constructor.

toStringback to summary
public String toString()

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