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

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ResultSetNode
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
FromTable, MaterializeSubqueryNode, SelectNode

public abstract class ResultSetNode
extends QueryTreeNode

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.

Author:
Jeff Lichtman

Field Summary
(package private)  CostEstimate costEstimate
           
(package private)  boolean cursorTargetTable
           
(package private)  boolean insertSource
           
(package private)  Optimizer optimizer
           
(package private)  JBitSet referencedTableMap
           
(package private)  ResultColumnList resultColumns
           
(package private)  int resultSetNumber
           
(package private)  CostEstimate scratchCostEstimate
           
(package private)  boolean 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
ResultSetNode()
           
 
Method Summary
 Visitable accept(Visitor v)
          Accept a visitor, and call v.visit() on child nodes as necessary.
 ResultSetNode addNewPredicate(Predicate predicate)
          Add a new predicate to the list.
 void assignResultSetNumber()
          Assign the next resultSetNumber to the resultSetNumber in this ResultSetNode.
 void bindExpressions(FromList fromListParam)
          Bind the expressions in this ResultSetNode.
 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 bindResultColumns(FromList fromListParam)
          Bind the result columns of this ResultSetNode when there is no base table to bind them to.
 void bindResultColumns(TableDescriptor targetTableDescriptor, FromVTI targetVTI, ResultColumnList targetColumnList, DMLStatementNode statement, FromList fromListParam)
          Bind the result columns for this ResultSetNode to a base table.
 void bindTargetExpressions(FromList fromListParam)
          Bind the expressions in the target list.
 void bindUntypedNullsToResultColumns(ResultColumnList rcl)
          Bind untyped nulls to the types in the given ResultColumnList.
 ResultSetNode bindVTITables(FromList fromListParam)
          Bind the VTI tables in this ResultSetNode.
 ResultSetNode changeAccessPath()
          The optimizer's decision on the access path for a result set may require the generation of extra result sets.
(package private)  void closeMethodArgument(ExpressionClassBuilder acb, MethodBuilder mb)
          This utility method is used by result set nodes that can be statement nodes to determine what their final argument is; if they are the statement result set, and there is a current date/time request, then a method will have been generated.
(package private)  boolean columnTypesAndLengthsMatch()
           
 ResultSetNode 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.)
(package private) abstract  void decrementLevel(int decrement)
          Decrement (query block) level (0-based) for all of the tables in this ResultSet tree.
 ResultSetNode enhanceRCLForInsert(int numTargetColumns, int[] colMap, DataDictionary dataDictionary, TableDescriptor targetTD, FromVTI targetVTI)
          This ResultSet is the source for an Insert.
 ResultSetNode ensurePredicateList(int numTables)
          Ensure that the top of the RSN tree has a PredicateList.
 void fillInReferencedTableMap(JBitSet passedMap)
          Fill the referencedTableMap with this ResultSetNode.
 boolean flattenableInFromSubquery(FromList fromList)
          Evaluate whether or not the subquery in a FromSubquery is flattenable.
 void generateNormalizationResultSet(ActivationClassBuilder acb, MethodBuilder mb, int resultSetNumber, ResultDescription resultDescription)
          Generate the code for a NormalizeResultSet.
 void generateResultSet(ExpressionClassBuilder acb, MethodBuilder mb)
          General logic shared by Core compilation and by the Replication Filter compiler.
(package private)  ResultColumn genNewRCForInsert(TableDescriptor targetTD, FromVTI targetVTI, int columnNumber, DataDictionary dataDictionary)
          Generate the RC/expression for an unspecified column in an insert.
 NormalizeResultSetNode genNormalizeResultSetNode(ResultSetNode normalizeChild, boolean forUpdate)
          Put a NormalizeResultSetNode on top of the specified ResultSetNode.
 ResultSetNode genProjectRestrict()
          Put a ProjectRestrictNode on top of this ResultSetNode.
protected  ResultSetNode genProjectRestrict(int numTables)
          Put a ProjectRestrictNode on top of each FromTable in the FromList.
(package private)  ResultSetNode genProjectRestrictForReordering()
          Get a parent ProjectRestrictNode above us.
 ResultColumnList getAllResultColumns(TableName allTableName)
          Expand "*" into a ResultColumnList with all of the columns in the table's result list.
 CostEstimate getCostEstimate()
          Get the CostEstimate for this ResultSetNode.
(package private)  FromTable getCursorTargetTable()
          return the target table of an updatable cursor result set.
 CostEstimate getFinalCostEstimate()
          Get the final CostEstimate for this ResultSetNode.
 FromList getFromList()
          Get the FromList.
protected  FromTable getFromTableByName(java.lang.String name, java.lang.String schemaName, boolean exactMatch)
          Determine whether or not the specified name is an exposed name in the current query block.
 ResultColumn getMatchingColumn(ColumnReference 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.
protected  Optimizer getOptimizer(OptimizableList optList, OptimizablePredicateList predList, DataDictionary dataDictionary, RequiredRowOrdering requiredRowOrdering)
          Get an optimizer to use for this ResultSetNode.
 JBitSet getReferencedTableMap()
          Get the referencedTableMap for this ResultSetNode
 ResultColumnList getResultColumns()
          Get the resultColumns for this ResultSetNode
 int getResultSetNumber()
          Get the resultSetNumber in this ResultSetNode.
 boolean isNotExists()
          Return whether or not the underlying ResultSet tree is for a NOT EXISTS join.
 boolean isOneRowResultSet()
          Return whether or not the underlying ResultSet tree will return a single row, at most.
(package private)  boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, java.util.Vector fbtVector)
          Return whether or not the underlying ResultSet tree is ordered on the specified columns.
(package private)  boolean isPossibleDistinctScan()
          Is it possible to do a distinct scan on this ResultSet tree.
(package private)  boolean isUpdatableCursor(DataDictionary dd)
          Determine if this result set is updatable or not, for a cursor (i.e., is it a cursor-updatable select).
 JBitSet LOJgetReferencedTables(int numTables)
           
 ResultDescription makeResultDescription()
          Make a ResultDescription for use in a ResultSet.
(package private)  ResultColumnDescriptor[] makeResultDescriptors(ExecutionContext ec)
           
 boolean markAsCursorTargetTable()
          Mark this ResultSetNode as the target table of an updatable cursor.
(package private)  void markForDistinctScan()
          Mark the underlying scan as a distinct scan.
(package private)  void markOrderingDependent()
          Notify the underlying result set tree that the result is ordering dependent.
 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.
 ResultSetNode modifyAccessPaths()
          Modify the access paths according to the decisions the optimizer made.
(package private)  void notCursorTargetTable()
          Mark this ResultSetNode as *not* the target table of an updatable cursor.
(package private)  void notFlattenableJoin()
          Mark this node and its children as not being a flattenable join.
protected static int numDistinctAggregates(java.util.Vector aggregateVector)
          Count the number of distinct aggregates in the list.
 ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicates, double outerRows)
          Optimize a ResultSetNode.
 ValueNode parseDefault(java.lang.String defaultText)
          Parse a default and turn it into a query tree.
 boolean performMaterialization(JBitSet outerTables)
          Return whether or not to materialize this ResultSet tree.
 ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList)
          Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode.
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
(package private)  void projectResultColumns()
          Find the unreferenced result columns and project them out.
(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.
 boolean referencesTarget(java.lang.String name, boolean baseTable)
          Search to see if a query references the specifed table name.
 void rejectParameters()
          Check for (and reject) ?
 void rejectXMLValues()
          Check for (and reject) XML values directly under the ResultColumns.
 void renameGeneratedResultNames()
          Rename generated result column names as '1', '2' etc...
(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.
 void setInsertSource()
          Remember that this node is the source result set for an INSERT.
 void setReferencedTableMap(JBitSet newRTM)
          Set the referencedTableMap in this ResultSetNode
 void setResultColumns(ResultColumnList newRCL)
          Set the resultColumns in this ResultSetNode
 void setResultToBooleanTrueNode(boolean onlyConvertAlls)
          Set the result column for the subquery to a boolean true, Useful for transformations such as changing: where exists (select ... from ...)
(package private)  void setTableConstructorTypes(ResultColumnList typeColumns)
          Set the type of each parameter in the result column list for this table constructor.
(package private)  boolean subqueryReferencesTarget(java.lang.String name, boolean baseTable)
          Return whether or not this ResultSetNode contains a subquery with a reference to the specified target.
 java.lang.String toString()
          Convert this object to a String.
 int updateTargetLockMode()
          Get the lock mode for the target of an update statement (a delete or update).
 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.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, 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, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, referencesSessionSchema, resolveTableToSynonym, 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
 

Field Detail

resultSetNumber

int resultSetNumber

referencedTableMap

JBitSet referencedTableMap

resultColumns

ResultColumnList resultColumns

statementResultSet

boolean statementResultSet

cursorTargetTable

boolean cursorTargetTable

insertSource

boolean insertSource

costEstimate

CostEstimate costEstimate

scratchCostEstimate

CostEstimate scratchCostEstimate

optimizer

Optimizer optimizer
Constructor Detail

ResultSetNode

public ResultSetNode()
Method Detail

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 QueryTreeNode
Returns:
This object as a String

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 QueryTreeNode
Parameters:
depth - The depth of this node in the tree
Returns:
Nothing

getResultSetNumber

public int getResultSetNumber()
Get the resultSetNumber in this ResultSetNode. Expected to be set during generate().

Returns:
int The resultSetNumber.

getCostEstimate

public CostEstimate getCostEstimate()
Get the CostEstimate for this ResultSetNode.

Returns:
The CostEstimate for this ResultSetNode.

getFinalCostEstimate

public CostEstimate getFinalCostEstimate()
Get the final CostEstimate for this ResultSetNode.

Returns:
The final CostEstimate for this ResultSetNode.

assignResultSetNumber

public void assignResultSetNumber()
                           throws StandardException
Assign the next resultSetNumber to the resultSetNumber in this ResultSetNode. Expected to be done during generate().

Returns:
Nothing.
Throws:
StandardException - Thrown on error

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.

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

bindVTITables

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

Parameters:
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 ResultSetNode. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.

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.

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.

Returns:
Nothing
Throws:
StandardException - Thrown on error

setTableConstructorTypes

void setTableConstructorTypes(ResultColumnList typeColumns)
                        throws StandardException
Set the type of each parameter in the result column list for this table constructor.

Parameters:
typeColumns - The ResultColumnList containing the desired result types.
Throws:
StandardException - Thrown on error

setInsertSource

public void setInsertSource()
Remember that this node is the source result set for an INSERT.


verifySelectStarSubquery

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

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

getAllResultColumns

public ResultColumnList getAllResultColumns(TableName allTableName)
                                     throws StandardException
Expand "*" into a ResultColumnList with all of the columns in the table's result list.

Parameters:
allTableName - The qualifier on the "*"
Returns:
ResultColumnList The expanded list
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.

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

setResultToBooleanTrueNode

public void setResultToBooleanTrueNode(boolean onlyConvertAlls)
                                throws StandardException
Set the result column for the subquery to a boolean true, Useful for transformations such as changing: where exists (select ... from ...) to: where (select true from ...) NOTE: No transformation is performed if the ResultColumn.expression is already the correct boolean constant.

Parameters:
onlyConvertAlls - Boolean, whether or not to just convert *'s
Returns:
Nothing.
Throws:
StandardException - Thrown on error

getFromList

public FromList getFromList()
                     throws StandardException
Get the FromList. Create and return an empty FromList. (Subclasses which actuall have FromLists will override this.) This is useful because there is a FromList parameter to bindExpressions() which is used as the common FromList to bind against, allowing us to support correlation columns under unions in subqueries.

Returns:
FromList
Throws:
StandardException - Thrown on error

bindResultColumns

public void bindResultColumns(FromList fromListParam)
                       throws StandardException
Bind the result columns of this ResultSetNode when there is no base table to bind them to. This is useful for SELECT statements, where the result columns get their types from the expressions that live under them.

Parameters:
fromListParam - FromList to use/append to.
Returns:
Nothing
Throws:
StandardException - Thrown on error

bindResultColumns

public void bindResultColumns(TableDescriptor targetTableDescriptor,
                              FromVTI targetVTI,
                              ResultColumnList targetColumnList,
                              DMLStatementNode statement,
                              FromList fromListParam)
                       throws StandardException
Bind the result columns for this ResultSetNode to a base table. This is useful for INSERT and UPDATE statements, where the result columns get their types from the table being updated or inserted into. If a result column list is specified, then the verification that the result column list does not contain any duplicates will be done when binding them by name.

Parameters:
targetTableDescriptor - The TableDescriptor for the table being updated or inserted into
targetColumnList - 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.
statement - Calling DMLStatementNode (Insert or Update)
fromListParam - FromList to use/append to.
Returns:
Nothing
Throws:
StandardException - Thrown on error

bindUntypedNullsToResultColumns

public void bindUntypedNullsToResultColumns(ResultColumnList rcl)
                                     throws StandardException
Bind untyped nulls to the types in the given ResultColumnList. This is used for binding the nulls in row constructors and table constructors. In all other cases (as of the time of this writing), we do nothing.

Parameters:
rcl - The ResultColumnList with the types to bind nulls to
Throws:
StandardException - Thrown on error

preprocess

public ResultSetNode preprocess(int numTables,
                                GroupByList gbl,
                                FromList fromList)
                         throws StandardException
Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode. o Putting the WHERE and HAVING clauses in conjunctive normal form (CNF). o Converting the WHERE and HAVING clauses into PredicateLists and classifying them. o Ensuring that a ProjectRestrictNode is generated on top of every FromBaseTable and generated in place of every FromSubquery. o Pushing single table predicates down to the new ProjectRestrictNodes.

Parameters:
numTables - The number of tables in the DML Statement
gbl - The group by list, if any
fromList - The from list, if any
Returns:
ResultSetNode at top of preprocessed tree.
Throws:
StandardException - Thrown on error

projectResultColumns

void projectResultColumns()
                    throws StandardException
Find the unreferenced result columns and project them out.

Throws:
StandardException

ensurePredicateList

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

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.

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. (ie, not a RowResultSetNode or 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.

Parameters:
fromList - The outer from list
Returns:
boolean Whether or not the FromSubquery is flattenable.

genProjectRestrictForReordering

ResultSetNode genProjectRestrictForReordering()
                                        throws StandardException
Get a parent ProjectRestrictNode above us. This is useful when we need to preserve the user specified column order when reordering the columns in the distinct when we combine an order by with a distinct.

Returns:
A parent ProjectRestrictNode to do column reordering
Throws:
StandardException - Thrown on error

optimize

public ResultSetNode optimize(DataDictionary dataDictionary,
                              PredicateList predicates,
                              double outerRows)
                       throws StandardException
Optimize a ResultSetNode. This means choosing the best access path for each table under the ResultSetNode, among other things. The only RSNs that need to implement their own optimize() are a SelectNode and those RSNs that can appear above a SelectNode in the query tree. Currently, a ProjectRestrictNode is the only RSN that can appear above a SelectNode.

Parameters:
dataDictionary - The DataDictionary to use for optimization
outerRows - The number of outer joining rows
Returns:
ResultSetNode The top of the optimized query tree
Throws:
StandardException - Thrown on error

modifyAccessPaths

public ResultSetNode modifyAccessPaths()
                                throws StandardException
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:
The modified query tree
Throws:
StandardException - Thrown on error

makeResultDescriptors

ResultColumnDescriptor[] makeResultDescriptors(ExecutionContext ec)

columnTypesAndLengthsMatch

boolean columnTypesAndLengthsMatch()
                             throws StandardException
Throws:
StandardException

setResultColumns

public void setResultColumns(ResultColumnList newRCL)
Set the resultColumns in this ResultSetNode

Returns:
None.

getResultColumns

public ResultColumnList getResultColumns()
Get the resultColumns for this ResultSetNode

Returns:
ResultColumnList for this ResultSetNode

setReferencedTableMap

public void setReferencedTableMap(JBitSet newRTM)
Set the referencedTableMap in this ResultSetNode

Parameters:
newRTM - The new referencedTableMap for this ResultSetNode
Returns:
None.

getReferencedTableMap

public JBitSet getReferencedTableMap()
Get the referencedTableMap for this ResultSetNode

Returns:
JBitSet Referenced table map for this ResultSetNode

fillInReferencedTableMap

public void fillInReferencedTableMap(JBitSet passedMap)
Fill the referencedTableMap with this ResultSetNode.

Parameters:
passedMap - The table map to fill in.
Returns:
Nothing.

rejectParameters

public void rejectParameters()
                      throws StandardException
Check for (and reject) ? parameters directly under the ResultColumns. This is done for SELECT statements.

Returns:
Nothing
Throws:
StandardException - Thrown if a ? parameter found directly under a ResultColumn

rejectXMLValues

public void rejectXMLValues()
                     throws StandardException
Check for (and reject) XML values directly under the ResultColumns. This is done for SELECT/VALUES statements. We reject values in this case because JDBC does not define an XML type/binding and thus there's no standard way to pass such a type back to a JDBC application.

Returns:
Nothing
Throws:
StandardException - Thrown if an XML value found directly under a ResultColumn

renameGeneratedResultNames

public void renameGeneratedResultNames()
                                throws StandardException
Rename generated result column names as '1', '2' etc... These will be the result column names seen by JDBC clients.

Throws:
StandardException

markStatementResultSet

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


closeMethodArgument

void closeMethodArgument(ExpressionClassBuilder acb,
                         MethodBuilder mb)
This utility method is used by result set nodes that can be statement nodes to determine what their final argument is; if they are the statement result set, and there is a current date/time request, then a method will have been generated. Otherwise, a simple null is passed in to the result set method.


enhanceRCLForInsert

public ResultSetNode enhanceRCLForInsert(int numTargetColumns,
                                         int[] colMap,
                                         DataDictionary dataDictionary,
                                         TableDescriptor targetTD,
                                         FromVTI targetVTI)
                                  throws StandardException
This ResultSet is the source for an Insert. The target RCL is in a different order and/or a superset of this RCL. In most cases we will reorder and/or add defaults to the current RCL so that is matches the target RCL. Those RSNs whose generate() method does not handle projects will insert a PRN, with a new RCL which matches the target RCL, above the current RSN. NOTE - The new or enhanced RCL will be fully bound.

Parameters:
numTargetColumns - # of columns in target RCL
dataDictionary - DataDictionary to use
targetTD - TableDescriptor for target if the target is not a VTI, null if a VTI
targetVTI - Target description if it is a VTI, null if not a VTI
Returns:
ResultSetNode The new top of the tree
Throws:
StandardException - Thrown on error

genNewRCForInsert

ResultColumn genNewRCForInsert(TableDescriptor targetTD,
                               FromVTI targetVTI,
                               int columnNumber,
                               DataDictionary dataDictionary)
                         throws StandardException
Generate the RC/expression for an unspecified column in an insert. Use the default if one exists.

Parameters:
targetTD - Target TableDescriptor if the target is not a VTI, null if a VTI.
targetVTI - Target description if it is a VTI, null if not a VTI
columnNumber - The column number
dataDictionary - The DataDictionary
Returns:
The RC/expression for the unspecified column.
Throws:
StandardException - Thrown on error

parseDefault

public ValueNode parseDefault(java.lang.String defaultText)
                       throws StandardException
Parse a default and turn it into a query tree.

Parameters:
defaultText - Text of Default.
Returns:
The parsed default as a query tree.
Throws:
StandardException - Thrown on failure

makeResultDescription

public ResultDescription makeResultDescription()
Make a ResultDescription for use in a ResultSet. This is useful when generating/executing a NormalizeResultSet, since it can appear anywhere in the tree.

Overrides:
makeResultDescription in class QueryTreeNode
Returns:
A ResultDescription for this ResultSetNode.

isUpdatableCursor

boolean isUpdatableCursor(DataDictionary dd)
                    throws StandardException
Determine if this result set is updatable or not, for a cursor (i.e., is it a cursor-updatable select). This returns false and we expect selectnode to refine it for further checking.

Throws:
StandardException - Thrown on error

getCursorTargetTable

FromTable getCursorTargetTable()
return the target table of an updatable cursor result set. since this is not updatable, just return null.


markAsCursorTargetTable

public boolean markAsCursorTargetTable()
Mark this ResultSetNode as the target table of an updatable cursor. Most types of ResultSetNode can't be target tables.

Returns:
true if the target table supports positioned updates.

notCursorTargetTable

void notCursorTargetTable()
Mark this ResultSetNode as *not* the target table of an updatable cursor.


genProjectRestrict

public ResultSetNode genProjectRestrict()
                                 throws StandardException
Put a ProjectRestrictNode on top of this ResultSetNode. 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.) This is useful for UNIONs, where we want to generate a DistinctNode above the UnionNode to eliminate the duplicates, because DistinctNodes expect their immediate child to be a PRN.

Returns:
The generated ProjectRestrictNode atop the original ResultSetNode.
Throws:
StandardException - Thrown on error

genProjectRestrict

protected ResultSetNode genProjectRestrict(int numTables)
                                    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.

Parameters:
numTables - Number of tables in the DML Statement
Returns:
The generated ProjectRestrictNode atop the original FromTable.
Throws:
StandardException - Thrown on error

genNormalizeResultSetNode

public NormalizeResultSetNode genNormalizeResultSetNode(ResultSetNode normalizeChild,
                                                        boolean forUpdate)
                                                 throws StandardException
Put a NormalizeResultSetNode on top of the specified ResultSetNode. 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 NRSN 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.) This is useful for UNIONs, where we want to generate a DistinctNode above the UnionNode to eliminate the duplicates, because the type going into the sort has to agree with what the sort expects. (insert into t1 (smallintcol) values 1 union all values 2;

Parameters:
normalizeChild - Child result set for new NRSN.
forUpdate - If the normalize result set is being used as a child for an update statement, then this is true.
Returns:
The generated NormalizeResultSetNode atop the original UnionNode.
Throws:
StandardException - Thrown on error
See Also:
NormalizeResultSetNode.init(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)

generateNormalizationResultSet

public void generateNormalizationResultSet(ActivationClassBuilder acb,
                                           MethodBuilder mb,
                                           int resultSetNumber,
                                           ResultDescription resultDescription)
                                    throws StandardException
Generate the code for a NormalizeResultSet. The call must push two items before calling this method
  1. pushGetResultSetFactoryExpression
  2. the expression to normalize

Parameters:
acb - The ActivationClassBuilder
mb - The method to put the generated code in
resultSetNumber - The result set number for the NRS
resultDescription - The ERD for the ResultSet
Throws:
StandardException - Thrown on error

changeAccessPath

public ResultSetNode changeAccessPath()
                               throws StandardException
The optimizer's decision on the access path for a result set may require the generation of extra result sets. For example, if it chooses an index for a FromBaseTable, we need an IndexToBaseRowNode above the FromBaseTable (and the FromBaseTable has to change its column list to match the index. This method in the parent class does not generate any extra result sets. It may be overridden in child classes.

Returns:
A ResultSetNode tree modified to do any extra processing for the chosen access path
Throws:
StandardException - Thrown on error

referencesTarget

public boolean referencesTarget(java.lang.String name,
                                boolean baseTable)
                         throws StandardException
Search to see if a query references the specifed table name.

Parameters:
name - Table name (String) to search for.
baseTable - Whether or not name is for a base table
Returns:
true if found, else false
Throws:
StandardException - Thrown on error

subqueryReferencesTarget

boolean subqueryReferencesTarget(java.lang.String name,
                                 boolean baseTable)
                           throws StandardException
Return whether or not this ResultSetNode contains a subquery with a reference to the specified target.

Parameters:
name - The table name.
Returns:
boolean Whether or not a reference to the table was found.
Throws:
StandardException - Thrown on error

isOneRowResultSet

public boolean isOneRowResultSet()
                          throws StandardException
Return whether or not the underlying ResultSet tree will return a single row, at most. This is important for join nodes where we can save the extra next on the right side if we know that it will return at most 1 row.

Returns:
Whether or not the underlying ResultSet tree will return a single row.
Throws:
StandardException - Thrown on error

isNotExists

public boolean isNotExists()
Return whether or not the underlying ResultSet tree is for a NOT EXISTS join.

Returns:
Whether or not the underlying ResultSet tree if for NOT EXISTS.

getOptimizer

protected Optimizer getOptimizer(OptimizableList optList,
                                 OptimizablePredicateList predList,
                                 DataDictionary dataDictionary,
                                 RequiredRowOrdering requiredRowOrdering)
                          throws StandardException
Get an optimizer to use for this ResultSetNode. Only get it once - subsequent calls return the same optimizer.

Throws:
StandardException - Thrown on error

getNewCostEstimate

protected CostEstimate getNewCostEstimate()
                                   throws StandardException
Get a cost estimate to use for this ResultSetNode.

Throws:
StandardException - Thrown on error

accept

public Visitable accept(Visitor v)
                 throws StandardException
Accept a visitor, and call v.visit() on child nodes as necessary.

Specified by:
accept in interface Visitable
Overrides:
accept in class QueryTreeNode
Parameters:
v - the visitor
Throws:
StandardException - on error

considerMaterialization

public ResultSetNode considerMaterialization(JBitSet outerTables)
                                      throws StandardException
Consider materialization for this ResultSet tree if it is valid and cost effective (It is not valid if incorrect results would be returned.)

Returns:
Top of the new/same ResultSet tree.
Throws:
StandardException - Thrown on error

performMaterialization

public boolean performMaterialization(JBitSet outerTables)
                               throws StandardException
Return whether or not to materialize this ResultSet tree.

Returns:
Whether or not to materialize this ResultSet tree. would return valid results.
Throws:
StandardException - Thrown on error

getFromTableByName

protected FromTable getFromTableByName(java.lang.String name,
                                       java.lang.String schemaName,
                                       boolean exactMatch)
                                throws StandardException
Determine whether or not the specified name is an exposed name in the current query block.

Parameters:
name - The specified name to search for as an exposed name.
schemaName - Schema name, if non-null.
exactMatch - Whether or not we need an exact match on specified schema and table names or match on table id.
Returns:
The FromTable, if any, with the exposed name.
Throws:
StandardException - Thrown on error

decrementLevel

abstract void decrementLevel(int decrement)
Decrement (query block) level (0-based) for all of the tables in this ResultSet tree. This is useful when flattening a subquery.

Parameters:
decrement - The amount to decrement by.
Returns:
Nothing;

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.

Parameters:
orderByList - The order by list
Returns:
Nothing.

generateResultSet

public void generateResultSet(ExpressionClassBuilder acb,
                              MethodBuilder mb)
                       throws StandardException
General logic shared by Core compilation and by the Replication Filter compiler. A couple ResultSets (the ones used by PREPARE SELECT FILTER) implement this method.

Throws:
StandardException - Thrown on error

updateTargetLockMode

public int updateTargetLockMode()
Get the lock mode for the target of an update statement (a delete or update). The update mode will always be row for CurrentOfNodes. It will be table if there is no where clause.

Returns:
The lock mode
See Also:
TransactionController

notFlattenableJoin

void notFlattenableJoin()
Mark this node and its children as not being a flattenable join.

Returns:
Nothing.

isOrderedOn

boolean isOrderedOn(ColumnReference[] crs,
                    boolean permuteOrdering,
                    java.util.Vector fbtVector)
              throws StandardException
Return whether or not the underlying ResultSet tree is ordered on the specified columns. RESOLVE - This method currently only considers the outermost table of the query block.

Parameters:
crs - The specified ColumnReference[]
permuteOrdering - Whether or not the order of the CRs in the array can be permuted
fbtVector - Vector that is to be filled with the FromBaseTable
Returns:
Whether the underlying ResultSet tree is ordered on the specified column.
Throws:
StandardException - Thrown on error

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

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

replaceDefaults

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

Parameters:
ttd - The TableDescriptor for the target table.
tcl - The RCL for the target table.
Throws:
StandardException - Thrown on error

isPossibleDistinctScan

boolean isPossibleDistinctScan()
Is it possible to do a distinct scan on this ResultSet tree. (See SelectNode for the criteria.)

Returns:
Whether or not it is possible to do a distinct scan on this ResultSet tree.

markForDistinctScan

void markForDistinctScan()
Mark the underlying scan as a distinct scan.

Returns:
Nothing.

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

Returns:
Nothing.

numDistinctAggregates

protected static final int numDistinctAggregates(java.util.Vector aggregateVector)
Count the number of distinct aggregates in the list. By 'distinct' we mean aggregates of the form:

LOJgetReferencedTables

public JBitSet LOJgetReferencedTables(int numTables)
                               throws StandardException
Throws:
StandardException

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

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