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

pack-priv Class SelectNode

extends ResultSetNode
Class Inheritance
Imports
java.util.ArrayList, .HashSet, .List, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.Limits, .SQLState, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.sql.compile.CompilerContext, .CostEstimate, .OptimizableList, .OptimizablePredicateList, .Optimizer, .OptimizerFactory, .OptimizerPlan, .RequiredRowOrdering, .Visitor, org.apache.derby.iapi.sql.conn.Authorizer, org.apache.derby.iapi.sql.dictionary.DataDictionary, .TableDescriptor, org.apache.derby.iapi.util.JBitSet, org.apache.derby.shared.common.sanity.SanityManager

A SelectNode represents the result set for any of the basic DML operations: SELECT, INSERT, UPDATE, and DELETE. (A RowResultSetNode will be used for an INSERT with a VALUES clause.) For INSERT - SELECT, any of the fields in a SelectNode can be used (the SelectNode represents the SELECT statement in the INSERT - SELECT). For UPDATE and DELETE, there will be one table in the fromList, and the groupByList fields will be null. For both INSERT and UPDATE, the resultColumns in the selectList will contain the names of the columns being inserted into or updated.

Field Summary

Modifier and TypeField and Description
private boolean
pack-priv FromList
fromList

List of tables in the FROM clause of this SELECT

pack-priv GroupByList
groupByList

List of result columns in GROUP BY clause

private List<AggregateNode>
havingAggregates

Aggregates in the HAVING clause.

pack-priv ValueNode
pack-priv SubqueryList
private boolean
private int
private boolean
pack-priv boolean
pack-priv ValueNode
pack-priv boolean
pack-priv OptimizerPlan
overridingPlan

Full plan for this SELECT as specified in an optimizer override

private FromList
pack-priv ResultSetNode.QueryExpressionClauses
private List<AggregateNode>
selectAggregates

Aggregates in the SELECT list.

pack-priv SubqueryList
pack-priv FromTable
private boolean
wasGroupBy

User specified a group by without aggregates and we turned it into a select distinct

private List<AggregateNode>
whereAggregates

Aggregates in the WHERE clause.

pack-priv ValueNode
whereClause

The ValueNode for the WHERE clause must represent a boolean expression.

pack-priv PredicateList
pack-priv SubqueryList
pack-priv List<WindowFunctionNode>
windowFuncCalls

List of window function calls (e.g. ROW_NUMBER, AVG(i), DENSE_RANK).

pack-priv WindowList
windows

List of windows.

Constructor Summary

AccessConstructor and Description
pack-priv
SelectNode(ResultColumnList selectList, FromList fromList, ValueNode whereClause, GroupByList groupByList, ValueNode havingClause, WindowList windowDefinitionList, OptimizerPlan overridingPlan, ContextManager cm)

Method Summary

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

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

Accept the visitor for all visitable children of this node.

private WindowList
pack-priv ResultSetNode

Returns:

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

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

Add a new predicate to the list.

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

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

Bind the expressions in this SelectNode.

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

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

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
)

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

Bind the tables in this SelectNode.

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

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

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

pack-priv void
bindTargetExpressions(FromList fromListParam)

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

Bind the expressions in the target list.

pack-priv void
bindUntypedNullsToResultColumns(ResultColumnList
The ResultColumnList with the types to bind to.
bindingRCL
)

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

Bind any untyped null nodes to the types in the given ResultColumnList.

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

Implements abstract org.apache.derby.impl.sql.compile.ResultSetNode.decrementLevel.

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

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
)

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

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

pack-priv ColumnReference

Returns:

ColumnReference ColumnReference to the column, if found
findColumnReferenceInResult
(String
Name of the column
colName
)

Find colName in the result columns and return underlying columnReference.

pack-priv boolean

Returns:

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

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

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

pack-priv ResultSetNode

Returns:

ResultSetNode new ResultSetNode atop the query tree.
genProjectRestrict
(int
The size of the original FROM list, before generation of join tree.
origFromListSize
)

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

Replace this SelectNode with a ProjectRestrictNode, since it has served its purpose.

pack-priv FromTable
getCursorTargetTable()

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

Assumes that isCursorUpdatable has been called, and that it is only called for updatable cursors.

pack-priv CostEstimate

Returns:

The final CostEstimate for this SelectNode, which is the final cost estimate for the best join order of this SelectNode's optimizer.
getFinalCostEstimate
()

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

Get the final CostEstimate for this SelectNode.

pack-priv FromList

Returns:

FromList The fromList for this SelectNode.
getFromList
()

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

Return the fromList for this SelectNode.

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
)

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

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

private Optimizer
getOptimizer(OptimizableList optList, OptimizablePredicateList predList, DataDictionary dataDictionary, RequiredRowOrdering requiredRowOrdering, OptimizerPlan overridingPlan)

Get an optimizer to use for this SelectNode.

pack-priv SubqueryList

Returns:

SubqueryList The selectSubquerys for this SelectNode.
getSelectSubquerys
()

Return the selectSubquerys for this SelectNode.

pack-priv ValueNode

Returns:

ValueNode The whereClause for this SelectNode.
getWhereClause
()

Return the whereClause for this SelectNode.

pack-priv PredicateList

Returns:

PredicateList The wherePredicates for this SelectNode.
getWherePredicates
()

Return the wherePredicates for this SelectNode.

pack-priv SubqueryList

Returns:

SubqueryList The whereSubquerys for this SelectNode.
getWhereSubquerys
()

Return the whereSubquerys for this SelectNode.

pack-priv boolean

Returns:

true if there are aggregates in the select list.
hasAggregatesInSelectList
()

pack-priv boolean
pack-priv boolean
pack-priv boolean

Returns:

true if this select node has any windows on it
hasWindows
()

Used by SubqueryNode to avoid flattening of a subquery if a window is defined on it.

private boolean

Returns:

boolean Whether or not this node returns an ordered result set.
isOrderedResult
(ResultColumnList resultColumns, ResultSetNode newTopRSN, boolean permuteOrdering)

Is the result of this node an ordered result set.

pack-priv boolean
isUpdatableCursor(DataDictionary dd)

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

Determine if this select is updatable or not, for a cursor.

pack-priv void
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
)

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

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

pack-priv ResultSetNode

Returns:

A QueryTree with the necessary modifications made
modifyAccessPaths
()

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

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

private ValueNode
normExpressions(ValueNode
clause to normalize
boolClause
)

Put the expression trees in conjunctive normal form

pack-priv ResultSetNode

Returns:

ResultSetNode The top of the optimized tree
optimize
(DataDictionary
The DataDictionary to use for optimization
dataDictionary
,
PredicateList
The predicate list to optimize against
predicateList
,
double
The number of outer joining rows
outerRows
)

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

Optimize this SelectNode.

private void
performTransitiveClosure(int
The number of tables in the query
numTables
)

Peform the various types of transitive closure on the where clause.

pack-priv ResultSetNode

Returns:

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

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

Prints the sub-nodes of this object.

pack-priv void
pushExpressionsIntoSelect(Predicate
The predicate that we attempt to push
predicate
)

Push an expression into this SELECT (and possibly down into one of the tables in the FROM list).

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
)

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

Push down the offset and fetch first parameters to this node.

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

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

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.

public void
pushQueryExpressionSuffix()

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

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

public boolean

Returns:

true if references SESSION schema tables, else false
referencesSessionSchema
()

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

Return true if the node references SESSION schema tables (temporary or permanent)

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
)

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

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

pack-priv void
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
)

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

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

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

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

pack-priv String
pack-priv boolean

Returns:

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

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

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

public String

Returns:

This object as a String
toString
()

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

Convert this object to a String.

pack-priv boolean

Returns:

Whether or not this subquery can be flattened based on a uniqueness condition.
uniqueSubquery
(boolean
Whether or not the column returned by this select, if it is a ColumnReference, is in an equality comparison.
additionalEQ
)

Determine whether or not this subquery, the SelectNode is in a subquery, can be flattened into the outer query block based on a uniqueness condition.

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

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

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

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

Inherited from org.apache.derby.impl.sql.compile.ResultSetNode:
adjustForSortEliminationadjustForSortEliminationassignResultSetNumberbindVTITableschangeAccessPathcolumnTypesAndLengthsMatchconsiderMaterializationenhanceRCLForInsertfillInReferencedTableMapgenerateNormalizationResultSetgenerateResultSetgenProjectRestrictgenProjectRestrictForReorderinggetAllResultColumnsgetCandidateFinalCostEstimategetCostEstimategetMatchingColumngetNewCostEstimategetOptimizergetOptimizerImplgetRCLForInsertgetReferencedTableMapgetResultColumnsgetResultSetNumbergetScratchCostEstimateisCursorTargetTableisInsertSourceisNotExistsisOneRowResultSetisOrderedOnisPossibleDistinctScanisStatementResultSetLOJgetReferencedTablesmakeResultDescriptionmakeResultDescriptorsmarkAsCursorTargetTablemarkForDistinctScanmarkStatementResultSetnotCursorTargetTablenotFlattenableJoinnumDistinctAggregatesparseDefaultperformMaterializationprintQueryExpressionSuffixClausesprojectResultColumnsrejectXMLValuesrenameGeneratedResultNamessetCandidateFinalCostEstimatesetCostEstimatesetCursorTargetTablesetInsertSourcesetOptimizersetReferencedTableMapsetResultColumnssetResultSetNumbersetResultToBooleanTrueNodesetScratchCostEstimatesetTableConstructorTypes