org.apache.derby.impl.sql.compile
Class RowResultSetNode

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ResultSetNode
          extended byorg.apache.derby.impl.sql.compile.FromTable
              extended byorg.apache.derby.impl.sql.compile.RowResultSetNode
All Implemented Interfaces:
Optimizable, Visitable

public class RowResultSetNode
extends FromTable

A RowResultSetNode represents the result set for a VALUES clause.

Author:
Jerry Brenner

Field Summary
(package private)  java.util.Vector aggregateVector
           
(package private)  OrderByList orderByList
           
(package private)  SubqueryList subquerys
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.FromTable
bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, loadFactor, maxCapacity, tableNumber, tableProperties, trulyTheBestAccessPath, userSpecifiedJoinStrategy
 
Fields inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
costEstimate, cursorTargetTable, insertSource, optimizer, referencedTableMap, resultColumns, resultSetNumber, scratchCostEstimate, statementResultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset
 
Constructor Summary
RowResultSetNode()
           
 
Method Summary
 ResultSetNode addNewPredicate(Predicate predicate)
          Add a new predicate to the list.
 void bindExpressions(FromList fromListParam)
          Bind the expressions in this RowResultSetNode.
 void bindExpressionsWithTables(FromList fromListParam)
          Bind the expressions in this ResultSetNode if it has tables.
 ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam)
          Bind the non VTI tables in this ResultSetNode.
 void bindTargetExpressions(FromList fromListParam)
          Bind the expressions in the target list.
 void bindUntypedNullsToResultColumns(ResultColumnList bindingRCL)
          Bind any untyped null nodes to the types in the given ResultColumnList.
private  boolean canWeCacheResults()
           
 ResultSetNode ensurePredicateList(int numTables)
          Ensure that the top of the RSN tree has a PredicateList.
 CostEstimate estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering)
          Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate.
 boolean flattenableInFromSubquery(FromList fromList)
          Evaluate whether or not the subquery in a FromSubquery is flattenable.
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          The generated ResultSet will be: RowResultSet -- for the VALUES clause
 java.lang.String getExposedName()
          Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.
 ResultColumn getMatchingColumn(ColumnReference columnReference)
          Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.
 void init(java.lang.Object valuesClause, java.lang.Object tableProperties)
          Initializer for a RowResultSetNode.
(package private)  void markOrderingDependent()
          Notify the underlying result set tree that the result is ordering dependent.
 Optimizable modifyAccessPath(JBitSet outerTables)
          Modify the access path for this Optimizable, as necessary.
 ResultSetNode modifyAccessPaths()
          Modify the access paths according to the decisions the optimizer made.
 ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicateList, double outerRows)
          Optimize this SelectNode.
(package private)  void optimizeSubqueries(DataDictionary dd, double rowCount)
          Optimize any subqueries that haven't been optimized any where else.
 ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList)
          Put a ProjectRestrictNode on top of each FromTable in the FromList.
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
(package private)  void pushOrderByList(OrderByList 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.
(package private)  void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl)
          Replace any DEFAULTs with the associated tree for the default.
(package private)  boolean returnsAtMostOneRow()
          Return whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics.
 java.lang.String statementToString()
           
 java.lang.String toString()
          Convert this object to a String.
 void verifySelectStarSubquery(FromList outerFromList, int subqueryType)
          Verify that a SELECT * is valid for this type of subquery.
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
areAllColumnsProjected, assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, decrementLevel, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCostEstimate, getCurrentAccessPath, getFromTableByName, getLevel, getName, getNumColumnsReturned, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasTableNumber, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsage, needsSpecialRCLBinding, nextAccessPath, optimizeIt, pullOptPredicates, pushExpressions, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setAllColumnsProjected, setCostEstimate, setHashKeyColumns, setLevel, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, uniqueJoin, verifyProperties
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
accept, assignResultSetNumber, bindResultColumns, bindResultColumns, bindVTITables, changeAccessPath, closeMethodArgument, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, generateNormalizationResultSet, generateResultSet, genNewRCForInsert, genNormalizeResultSetNode, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getCursorTargetTable, getFinalCostEstimate, getFromList, getNewCostEstimate, getOptimizer, getReferencedTableMap, getResultColumns, getResultSetNumber, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, projectResultColumns, referencesTarget, rejectParameters, renameGeneratedResultNames, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes, subqueryReferencesTarget, updateTargetLockMode
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, referencesSessionSchema, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.sql.compile.Optimizable
getDataDictionary, getReferencedTableMap, getResultSetNumber
 

Field Detail

subquerys

SubqueryList subquerys

aggregateVector

java.util.Vector aggregateVector

orderByList

OrderByList orderByList
Constructor Detail

RowResultSetNode

public RowResultSetNode()
Method Detail

init

public void init(java.lang.Object valuesClause,
                 java.lang.Object tableProperties)
Initializer for a RowResultSetNode.

Overrides:
init in class FromTable
Parameters:
valuesClause - The result column list for the VALUES clause.
tableProperties - Properties list associated with the table

toString

public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class FromTable
Returns:
This object as a String

statementToString

public java.lang.String statementToString()

printSubNodes

public void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Overrides:
printSubNodes in class ResultSetNode
Parameters:
depth - The depth of this node in the tree
Returns:
Nothing

estimateCost

public CostEstimate estimateCost(OptimizablePredicateList predList,
                                 ConglomerateDescriptor cd,
                                 CostEstimate outerCost,
                                 Optimizer optimizer,
                                 RowOrdering rowOrdering)
                          throws StandardException
Description copied from interface: Optimizable
Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate. It is assumed that the predicate list has already been classified. This cost estimate is just for one scan, not for the life of the query.

Specified by:
estimateCost in interface Optimizable
Overrides:
estimateCost in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.estimateCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, org.apache.derby.iapi.sql.compile.CostEstimate, org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.RowOrdering)

bindNonVTITables

public ResultSetNode bindNonVTITables(DataDictionary dataDictionary,
                                      FromList fromListParam)
                               throws StandardException
Bind the non VTI tables in this ResultSetNode. This includes getting their descriptors from the data dictionary and numbering them.

Overrides:
bindNonVTITables in class ResultSetNode
Parameters:
dataDictionary - The DataDictionary to use for binding
fromListParam - FromList to use/append to.
Returns:
ResultSetNode
Throws:
StandardException - Thrown on error

bindExpressions

public void bindExpressions(FromList fromListParam)
                     throws StandardException
Bind the expressions in this RowResultSetNode. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.

Overrides:
bindExpressions in class ResultSetNode
Parameters:
fromListParam - FromList to use/append to.
Returns:
Nothing
Throws:
StandardException - Thrown on error

bindExpressionsWithTables

public void bindExpressionsWithTables(FromList fromListParam)
                               throws StandardException
Bind the expressions in this ResultSetNode if it has tables. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.

Overrides:
bindExpressionsWithTables in class ResultSetNode
Parameters:
fromListParam - FromList to use/append to.
Returns:
Nothing
Throws:
StandardException - Thrown on error

bindTargetExpressions

public void bindTargetExpressions(FromList fromListParam)
                           throws StandardException
Bind the expressions in the target list. This means binding the sub-expressions, as well as figuring out what the return type is for each expression. This is useful for EXISTS subqueries, where we need to validate the target list before blowing it away and replacing it with a SELECT true.

Overrides:
bindTargetExpressions in class ResultSetNode
Returns:
Nothing
Throws:
StandardException - Thrown on error

bindUntypedNullsToResultColumns

public void bindUntypedNullsToResultColumns(ResultColumnList bindingRCL)
                                     throws StandardException
Bind any untyped null nodes to the types in the given ResultColumnList.

Overrides:
bindUntypedNullsToResultColumns in class ResultSetNode
Parameters:
bindingRCL - The ResultColumnList with the types to bind to.
Throws:
StandardException - Thrown on error

getMatchingColumn

public ResultColumn getMatchingColumn(ColumnReference columnReference)
                               throws StandardException
Try to find a ResultColumn in the table represented by this FromTable that matches the name in the given ColumnReference.

Overrides:
getMatchingColumn in class ResultSetNode
Parameters:
columnReference - The columnReference whose name we're looking for in the given table.
Returns:
A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
Throws:
StandardException - Thrown on error

getExposedName

public java.lang.String getExposedName()
                                throws StandardException
Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.

Overrides:
getExposedName in class FromTable
Returns:
The exposed name of this table.
Throws:
StandardException - Thrown on error

verifySelectStarSubquery

public void verifySelectStarSubquery(FromList outerFromList,
                                     int subqueryType)
                              throws StandardException
Verify that a SELECT * is valid for this type of subquery.

Overrides:
verifySelectStarSubquery in class ResultSetNode
Parameters:
outerFromList - The FromList from the outer query block(s)
subqueryType - The subquery type
Returns:
None
Throws:
StandardException - Thrown on error

pushOrderByList

void pushOrderByList(OrderByList 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.

Overrides:
pushOrderByList in class ResultSetNode
Parameters:
orderByList - The order by list
Returns:
Nothing.

preprocess

public ResultSetNode preprocess(int numTables,
                                GroupByList gbl,
                                FromList fromList)
                         throws StandardException
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.

Overrides:
preprocess in class ResultSetNode
Parameters:
numTables - Number of tables in the DML Statement
gbl - The group by list, if any
fromList - The from list, if any
Returns:
The generated ProjectRestrictNode atop the original FromTable.
Throws:
StandardException - Thrown on error

ensurePredicateList

public ResultSetNode ensurePredicateList(int numTables)
                                  throws StandardException
Ensure that the top of the RSN tree has a PredicateList.

Overrides:
ensurePredicateList in class ResultSetNode
Parameters:
numTables - The number of tables in the query.
Returns:
ResultSetNode A RSN tree with a node which has a PredicateList on top.
Throws:
StandardException - Thrown on error

addNewPredicate

public ResultSetNode addNewPredicate(Predicate predicate)
                              throws StandardException
Add a new predicate to the list. This is useful when doing subquery transformations, when we build a new predicate with the left side of the subquery operator and the subquery's result column.

Overrides:
addNewPredicate in class ResultSetNode
Parameters:
predicate - The predicate to add
Returns:
ResultSetNode The new top of the tree.
Throws:
StandardException - Thrown on error

flattenableInFromSubquery

public boolean flattenableInFromSubquery(FromList fromList)
Evaluate whether or not the subquery in a FromSubquery is flattenable. Currently, a FSqry is flattenable if all of the following are true: o Subquery is a SelectNode or a RowResultSetNode (not a UnionNode) o It contains no top level subqueries. (RESOLVE - we can relax this) o It does not contain a group by or having clause o It does not contain aggregates. o There is at least one result set in the from list that is not a RowResultSetNode (the reason is to avoid having an outer SelectNode with an empty FromList.

Overrides:
flattenableInFromSubquery in class ResultSetNode
Parameters:
fromList - The outer from list
Returns:
boolean Whether or not the FromSubquery is flattenable.

optimize

public ResultSetNode optimize(DataDictionary dataDictionary,
                              PredicateList predicateList,
                              double outerRows)
                       throws StandardException
Optimize this SelectNode. This means choosing the best access path for each table, among other things.

Overrides:
optimize in class ResultSetNode
Parameters:
dataDictionary - The DataDictionary to use for optimization
predicateList - The predicate list to optimize against
outerRows - The number of outer joining rows
Returns:
ResultSetNode The top of the optimized tree
Throws:
StandardException - Thrown on error

modifyAccessPath

public Optimizable modifyAccessPath(JBitSet outerTables)
                             throws StandardException
Description copied from interface: Optimizable
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

Specified by:
modifyAccessPath in interface Optimizable
Overrides:
modifyAccessPath in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.modifyAccessPath(org.apache.derby.iapi.util.JBitSet)

modifyAccessPaths

public ResultSetNode modifyAccessPaths()
                                throws StandardException
Description copied from class: ResultSetNode
Modify the access paths according to the decisions the optimizer made. This can include adding project/restrict nodes, index-to-base-row nodes, etc.

Overrides:
modifyAccessPaths in class ResultSetNode
Returns:
The modified query tree
Throws:
StandardException - Thrown on error
See Also:
ResultSetNode.modifyAccessPaths()

returnsAtMostOneRow

boolean returnsAtMostOneRow()
Return whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics. (A RowResultSetNode and a SELECT with a non-grouped aggregate will return at most 1 row.)

Overrides:
returnsAtMostOneRow in class ResultSetNode
Returns:
Whether or not this ResultSet tree is guaranteed to return at most 1 row based on heuristics.

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
The generated ResultSet will be: RowResultSet -- for the VALUES clause

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method for the generated code to go into
Returns:
A compiled Expression returning a ResultSet
Throws:
StandardException - Thrown on error

replaceDefaults

void replaceDefaults(TableDescriptor ttd,
                     ResultColumnList tcl)
               throws StandardException
Replace any DEFAULTs with the associated tree for the default.

Overrides:
replaceDefaults in class ResultSetNode
Parameters:
ttd - The TableDescriptor for the target table.
tcl - The RCL for the target table.
Throws:
StandardException - Thrown on error

optimizeSubqueries

void optimizeSubqueries(DataDictionary dd,
                        double rowCount)
                  throws StandardException
Optimize any subqueries that haven't been optimized any where else. This is useful for a RowResultSetNode as a derived table because it doesn't get optimized otherwise.

Overrides:
optimizeSubqueries in class FromTable
Returns:
Nothing.
Throws:
StandardException - Thrown on error

markOrderingDependent

void markOrderingDependent()
Notify the underlying result set tree that the result is ordering dependent. (For example, no bulk fetch on an index if under an IndexRowToBaseRow.)

Overrides:
markOrderingDependent in class ResultSetNode
Returns:
Nothing.

canWeCacheResults

private boolean canWeCacheResults()
                           throws StandardException
Throws:
StandardException


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.