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

public abstract Class ResultSetNode

extends QueryTreeNode
Class Inheritance
Known Direct Subclasses
org.apache.derby.impl.sql.compile.SelectNode, org.apache.derby.impl.sql.compile.FromTable, org.apache.derby.impl.sql.compile.MaterializeSubqueryNode
Imports
java.util.ArrayList, .List, .Set, org.apache.derby.catalog.types.DefaultInfoImpl, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, org.apache.derby.iapi.services.classfile.VMOpcode, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.sql.ResultColumnDescriptor, .ResultDescription, org.apache.derby.iapi.sql.compile.CompilerContext, .CostEstimate, .Optimizer, .OptimizerFactory, .Parser, .RequiredRowOrdering, .Visitable, .Visitor, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.iapi.sql.dictionary.ColumnDescriptor, .DataDictionary, .DefaultDescriptor, .TableDescriptor, org.apache.derby.iapi.store.access.TransactionController, org.apache.derby.iapi.types.DataTypeDescriptor, org.apache.derby.iapi.util.JBitSet, org.apache.derby.shared.common.sanity.SanityManager

A ResultSetNode represents a result set, that is, a set of rows. It is analogous to a ResultSet in the LanguageModuleExternalInterface. In fact, code generation for a a ResultSetNode will create a "new" call to a constructor for a ResultSet.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ResultSetNode.QueryExpressionClauses

For ease of pushing order by, offset and fetch first/next clauses into nodes.

Field Summary

Modifier and TypeField and Description
private CostEstimate
private CostEstimate
private boolean
private boolean
private Optimizer
private JBitSet
private ResultColumnList
private int
private CostEstimate
private boolean
Inherited from org.apache.derby.impl.sql.compile.QueryTreeNode:
AUTOINCREMENT_CREATE_MODIFYAUTOINCREMENT_CYCLEAUTOINCREMENT_INC_INDEXAUTOINCREMENT_IS_AUTOINCREMENT_INDEXAUTOINCREMENT_START_INDEX

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

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

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

Accept the visitor for all visitable children of this node.

pack-priv ResultSetNode

Returns:

ResultSetNode The new top of the tree.
addNewPredicate
(Predicate
The predicate to add
predicate
)

Add a new predicate to the list.

pack-priv void
adjustForSortElimination()

Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort.

pack-priv void
adjustForSortElimination(RequiredRowOrdering rowOrdering)

Same goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed.

pack-priv void
assignResultSetNumber()

Assign the next resultSetNumber to the resultSetNumber in this ResultSetNode.

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

Bind the expressions in this ResultSetNode.

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

Bind the expressions in this ResultSetNode if it has tables.

pack-priv ResultSetNode

Returns:

ResultSetNode
bindNonVTITables
(DataDictionary
The DataDictionary to use for binding
dataDictionary
,
FromList
FromList to use/append to.
fromListParam
)

Bind the non VTI tables in this ResultSetNode.

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

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
)

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

pack-priv void
bindTargetExpressions(FromList fromListParam)

Bind the expressions in the target list.

pack-priv void
bindUntypedNullsToResultColumns(ResultColumnList
The ResultColumnList with the types to bind nulls to
rcl
)

Bind untyped nulls to the types in the given ResultColumnList.

pack-priv ResultSetNode

Returns:

ResultSetNode
bindVTITables
(FromList
FromList to use/append to.
fromListParam
)

Bind the VTI tables in this ResultSetNode.

pack-priv ResultSetNode

Returns:

A ResultSetNode tree modified to do any extra processing for the chosen access path
changeAccessPath
()

The optimizer's decision on the access path for a result set may require the generation of extra result sets.

pack-priv boolean
pack-priv ResultSetNode

Returns:

Top of the new/same ResultSet tree.
considerMaterialization
(JBitSet outerTables)

Consider materialization for this ResultSet tree if it is valid and cost effective (It is not valid if incorrect results would be returned.)

private ResultColumn
createGeneratedColumn(TableDescriptor targetTD, ColumnDescriptor colDesc)

Create a ResultColumn for a column with a generation clause.

pack-priv abstract void
decrementLevel(int
The amount to decrement by.
decrement
)

Decrement (query block) level (0-based) for all of the tables in this ResultSet tree.

pack-priv ResultSetNode

Returns:

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

This ResultSet is the source for an Insert.

pack-priv ResultSetNode

Returns:

ResultSetNode A RSN tree with a node which has a PredicateList on top.
ensurePredicateList
(int
The number of tables in the query.
numTables
)

Ensure that the top of the RSN tree has a PredicateList.

pack-priv void
fillInReferencedTableMap(JBitSet
The table map to fill in.
passedMap
)

Fill the referencedTableMap with this ResultSetNode.

pack-priv boolean

Returns:

boolean Whether or not the FromSubquery is flattenable.
flattenableInFromSubquery
(FromList
The outer from list
fromList
)

Evaluate whether or not the subquery in a FromSubquery is flattenable.

pack-priv void
generateNormalizationResultSet(ActivationClassBuilder
The ActivationClassBuilder
acb
,
MethodBuilder
The method to put the generated code in
mb
,
int
The result set number for the NRS
resultSetNumber
,
ResultDescription
The ERD for the ResultSet
resultDescription
)

Generate the code for a NormalizeResultSet.

private ResultSetNode

Returns:

a ProjectRestrictNode whos RCL matches the target RCL
generateProjectRestrictForInsert
(InsertNode
the target node for the insert
target
,
int[]
int array representation of correspondence between RCLs - colmap[i] = -1 -> missing in current RCL colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
colMap
)

Generate a ProjectRestrictNode to put on top of this node if it's the source for an insert, and the RCL needs reordering and/or addition of columns in order to match the target RCL.

pack-priv void
generateResultSet(ExpressionClassBuilder
The ExpressionClassBuilder for the class being built
acb
,
MethodBuilder
The method the expression will go into
mb
)

General logic shared by Core compilation and by the Replication Filter compiler.

private ResultColumn

Returns:

The RC/expression for the unspecified column.
genNewRCForInsert
(TableDescriptor
Target TableDescriptor if the target is not a VTI, null if a VTI.
targetTD
,
FromVTI
Target description if it is a VTI, null if not a VTI
targetVTI
,
int
The column number
columnNumber
,
DataDictionary
The DataDictionary
dataDictionary
)

Generate the RC/expression for an unspecified column in an insert.

pack-priv ResultSetNode

Returns:

The generated ProjectRestrictNode atop the original ResultSetNode.
genProjectRestrict
()

Put a ProjectRestrictNode on top of this ResultSetNode.

pack-priv ResultSetNode

Returns:

The generated ProjectRestrictNode atop the original FromTable.
genProjectRestrict
(int
Number of tables in the DML Statement
numTables
)

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

pack-priv ResultSetNode

Returns:

A parent ProjectRestrictNode to do column reordering
genProjectRestrictForReordering
()

Get a parent ProjectRestrictNode above us.

pack-priv ResultColumnList

Returns:

ResultColumnList The expanded list, or null if allTableName is non-null and doesn't match a table name in this result set
getAllResultColumns
(TableName
The qualifier on the "*"
allTableName
)

Expand "*" into a ResultColumnList with all of the columns in the table's result list.

pack-priv CostEstimate
getCandidateFinalCostEstimate()

Get the final cost estimate which we've set so far

pack-priv CostEstimate

Returns:

The CostEstimate for this ResultSetNode.
getCostEstimate
()

Get the CostEstimate for this ResultSetNode.

pack-priv FromTable
getCursorTargetTable()

return the target table of an updatable cursor result set.

pack-priv CostEstimate

Returns:

The final CostEstimate for this ResultSetNode.
getFinalCostEstimate
()

Get the final CostEstimate for this ResultSetNode.

pack-priv FromList

Returns:

FromList
getFromList
()

Get the FromList.

pack-priv FromTable

Returns:

The FromTable, if any, with the exposed name.
getFromTableByName
(String
The specified name to search for as an exposed name.
name
,
String
Schema name, if non-null.
schemaName
,
boolean
Whether or not we need an exact match on specified schema and table names or match on table id.
exactMatch
)

Determine whether or not the specified name is an exposed name in the current query block.

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
)

Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.

protected CostEstimate
getNewCostEstimate()

Get a cost estimate to use for this ResultSetNode.

pack-priv Optimizer
getOptimizer()

Get the optimizer being used on this result set

protected OptimizerImpl

Returns:

If this.optimizer has has already been created by the getOptimizer() method above, then return it; otherwise, return null.
getOptimizerImpl
()

Get the optimizer for this result set.

pack-priv ResultColumnList

Returns:

an RCL that matches the target RCL
getRCLForInsert
(InsertNode
the target node for the insert
target
,
int[]
int array representation of correspondence between RCLs - colmap[i] = -1 -> missing in current RCL colmap[i] = j -> targetRCL(i) <-> thisRCL(j+1)
colMap
)

Generate an RCL that can replace the original RCL of this node to match the RCL of the target for the insert.

public JBitSet

Returns:

JBitSet Referenced table map for this ResultSetNode
getReferencedTableMap
()

Get the referencedTableMap for this ResultSetNode.

pack-priv ResultColumnList

Returns:

ResultColumnList for this ResultSetNode
getResultColumns
()

Get the resultColumns for this ResultSetNode

public int

Returns:

int The resultSetNumber.
getResultSetNumber
()

Get the resultSetNumber in this ResultSetNode.

pack-priv CostEstimate
getScratchCostEstimate()

Get the scratch estimate

pack-priv boolean
isCursorTargetTable()

Return true if this is a cursor target table

pack-priv boolean
isInsertSource()

Return true if this is the source result set for an INSERT

pack-priv boolean

Returns:

Whether or not the underlying ResultSet tree if for NOT EXISTS.
isNotExists
()

Return whether or not the underlying ResultSet tree is for a NOT EXISTS join.

pack-priv boolean

Returns:

Whether or not the underlying ResultSet tree will return a single row.
isOneRowResultSet
()

Return whether or not the underlying ResultSet tree will return a single row, at most.

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
)

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

pack-priv boolean

Returns:

Whether or not it is possible to do a distinct scan on this ResultSet tree.
isPossibleDistinctScan
(Set<BaseColumnNode>
the set of distinct columns
distinctColumns
)

Is it possible to do a distinct scan on this ResultSet tree.

pack-priv boolean
isStatementResultSet()

Return true if this is a statement result set

pack-priv boolean
isUpdatableCursor(DataDictionary dd)

Determine if this result set is updatable or not, for a cursor (i.e., is it a cursor-updatable select).

pack-priv JBitSet
LOJgetReferencedTables(int numTables)

public ResultDescription

Returns:

A ResultDescription for this ResultSetNode.
makeResultDescription
()

Make a ResultDescription for use in a ResultSet.

pack-priv ResultColumnDescriptor[]
pack-priv boolean

Returns:

true if the target table supports positioned updates.
markAsCursorTargetTable
()

Mark this ResultSetNode as the target table of an updatable cursor.

pack-priv void
markForDistinctScan()

Mark the underlying scan as a distinct scan.

pack-priv void
markStatementResultSet()

This method is overridden to allow a resultset node to know if it is the one controlling the statement -- i.e., it is the outermost result set node for the statement.

pack-priv ResultSetNode

Returns:

The modified query tree
modifyAccessPaths
()

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

pack-priv ResultSetNode

Returns:

The modified query tree
modifyAccessPaths
(PredicateList
A list of optimizable predicates that should be pushed to this ResultSetNode, as determined by optimizer.
predList
)

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

pack-priv void
notCursorTargetTable()

Mark this ResultSetNode as *not* the target table of an updatable cursor.

pack-priv void
notFlattenableJoin()

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

pack-priv static int

Returns:

number of aggregates
numDistinctAggregates
(List<AggregateNode> aggregates)

Count the number of distinct aggregates in the list.

pack-priv ResultSetNode

Returns:

ResultSetNode The top of the optimized query tree
optimize
(DataDictionary
The DataDictionary to use for optimization
dataDictionary
,
PredicateList
The PredicateList to apply.
predicates
,
double
The number of outer joining rows
outerRows
)

Optimize a ResultSetNode.

public ValueNode

Returns:

The parsed default as a query tree.
parseDefault
(String
Text of Default.
defaultText
)

Parse a default and turn it into a query tree.

pack-priv boolean

Returns:

Whether or not to materialize this ResultSet tree. would return valid results.
performMaterialization
(JBitSet outerTables)

Return whether or not to materialize this ResultSet tree.

pack-priv ResultSetNode

Returns:

ResultSetNode at top of preprocessed tree.
preprocess
(int
The number of tables in the DML Statement
numTables
,
GroupByList
The group by list, if any
gbl
,
FromList
The from list, if any
fromList
)

Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode.

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

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

Prints the sub-nodes of this object.

pack-priv void
projectResultColumns()

Find the unreferenced result columns and project them out.

pack-priv void
pushOffsetFetchFirst(ValueNode
the OFFSET, if any
offset
,
ValueNode
the OFFSET FIRST, if any
fetchFirst
,
boolean
true if the clauses were added by (and have the semantics of) a JDBC limit clause
hasJDBClimitClause
)

Push down the offset and fetch first parameters, if any.

pack-priv void
pushOrderByList(OrderByList
The order by list
orderByList
)

Push the order by list down from the cursor node into its child result set so that the optimizer has all of the information that it needs to consider sort avoidance.

pack-priv void
pushQueryExpressionSuffix()

Set up a new level for order by and fetch/offset clauses.

pack-priv boolean

Returns:

true if found, else false
referencesTarget
(String
Table name (String) to search for.
name
,
boolean
Whether or not name is for a base table
baseTable
)

Search to see if a query references the specifed table name.

pack-priv void
rejectParameters()

Check for (and reject) ?

pack-priv void
rejectXMLValues()

Check for (and reject) XML values directly under the ResultColumns.

pack-priv void
renameGeneratedResultNames()

Rename generated result column names as '1', '2' etc...

pack-priv void
replaceOrForbidDefaults(TableDescriptor
The TableDescriptor for the target table.
ttd
,
ResultColumnList
The RCL for the target table.
tcl
,
boolean
true if allowed
allowDefaults
)

Replace any DEFAULTs with the associated tree for the default if allowed, or flag (when inside top level set operator nodes).

pack-priv boolean

Returns:

Whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics.
returnsAtMostOneRow
()

Return whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics.

pack-priv void
setCandidateFinalCostEstimate(CostEstimate ce)

Set the final cost estimate

pack-priv void
setCostEstimate(CostEstimate ce)

Set the CostEstimate for this ResultSetNode

pack-priv void
setCursorTargetTable(boolean yesOrNo)

Set whether this is a cursor target table

pack-priv void
setInsertSource()

Remember that this node is the source result set for an INSERT.

pack-priv void
setOptimizer(Optimizer opt)

Set the optimizer for use on this result set

pack-priv void
setReferencedTableMap(JBitSet
The new referencedTableMap for this ResultSetNode
newRTM
)

Set the referencedTableMap in this ResultSetNode

pack-priv void
setResultColumns(ResultColumnList
The new ResultColumnList for this ResultSetNode
newRCL
)

Set the resultColumns in this ResultSetNode

pack-priv void
pack-priv ResultSetNode

Returns:

ResultSetNode whose resultColumn was transformed; defaults to "this" here, but can be overridden by subclasses.
setResultToBooleanTrueNode
(boolean
Boolean, whether or not to just convert *'s
onlyConvertAlls
)

Set the result column for the subquery to a boolean true, Useful for transformations such as changing: where exists (select ...

pack-priv void
setScratchCostEstimate(CostEstimate ce)

Set the scratch estimate

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

Set the type of each parameter in the result column list for this table constructor.

pack-priv boolean

Returns:

boolean Whether or not a reference to the table was found.
subqueryReferencesTarget
(String
The table name.
name
,
boolean baseTable)

Return whether or not this ResultSetNode contains a subquery with a reference to the specified target.

public String

Returns:

This object as a String
toString
()

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

Convert this object to a String.

pack-priv int

Returns:

The lock mode
updateTargetLockMode
()

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

pack-priv void
verifySelectStarSubquery(FromList
The FromList from the outer query block(s)
outerFromList
,
int
The subquery type
subqueryType
)

Verify that a SELECT * is valid for this type of subquery.

Inherited from org.apache.derby.impl.sql.compile.QueryTreeNode:
acceptaddTagaddUDTUsagePrivaddUDTUsagePrivbindOffsetFetchbindRowMultiSetbindUserCatalogTypebindUserTypecheckReliabilitycheckReliabilityconvertDefaultNodecopyTagsFromcreateTypeDependencydebugFlushdebugPrintdisablePrivilegeCollectionformatNodeStringgenerategenerateAuthorizeCheckgetBeginOffsetgetClassFactorygetCompilerContextgetContextgetContextManagergetDataDictionarygetDependencyManagergetEndOffsetgetExecutionFactorygetGenericConstantActionFactorygetIntPropertygetLanguageConnectionContextgetLongPropertygetNullNodegetOffsetOrderedNodesgetOptimizerFactorygetOptimizerTracergetParameterTypesgetSchemaDescriptorgetSchemaDescriptorgetStatementTypegetTableDescriptorgetTypeCompilergetUDTDescisAtomicisPrivilegeCollectionRequiredisSessionSchemaisSessionSchemamakeConstantActionmakeTableNamemakeTableNamenodeHeaderoptimizerTracingIsOnorReliabilityparseSearchConditionparseStatementprintLabelreferencesSessionSchemaresolveTableToSynonymsetBeginOffsetsetEndOffsetsetRefActionInfostackPrinttaggedWithtreePrinttreePrintverifyClassExist