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

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.SelectNode
All Implemented Interfaces:
Visitable

public class SelectNode
extends ResultSetNode

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.

Author:
Jeff Lichtman

Field Summary
private  boolean bindTargetListOnly
           
(package private)  FromList fromList
          List of tables in the FROM clause of this SELECT
private  boolean generatedForGroupByClause
           
private  boolean generatedForHavingClause
           
(package private)  GroupByList groupByList
          List of result columns in GROUP BY clause
private  boolean isDistinct
           
private  boolean orderByAndDistinctMerged
           
(package private)  OrderByList orderByList
           
(package private)  boolean orderByQuery
           
(package private)  ValueNode originalWhereClause
           
private  FromList preJoinFL
           
(package private)  java.util.Vector selectAggregates
           
(package private)  SubqueryList selectSubquerys
           
(package private)  FromTable targetTable
           
(package private)  java.util.Vector whereAggregates
           
(package private)  ValueNode whereClause
          The ValueNode for the WHERE clause must represent a boolean expression.
(package private)  PredicateList wherePredicates
           
(package private)  SubqueryList whereSubquerys
           
 
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
SelectNode()
           
 
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 bindExpressions(FromList fromListParam)
          Bind the expressions in this SelectNode.
 void bindExpressionsWithTables(FromList fromListParam)
          Bind the expressions in this ResultSetNode if it has tables.
 ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam)
          Bind the tables in this SelectNode.
 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 bindingRCL)
          Bind any untyped null nodes to the types in the given ResultColumnList.
 void clearDistinct()
           
(package private)  void decrementLevel(int decrement)
          Decrement (query block) level (0-based) for all of the tables in this ResultSet tree.
 ResultSetNode ensurePredicateList(int numTables)
          Ensure that the top of the RSN tree has a PredicateList.
 boolean flattenableInFromSubquery(FromList fromList)
          Evaluate whether or not the subquery in a FromSubquery is flattenable.
 ResultSetNode genProjectRestrict(int origFromListSize)
          Replace this SelectNode with a ProjectRestrictNode, since it has served its purpose.
 java.util.Vector getAggregateVector(int clause)
          Return the specified aggregate vector for this SelectNode.
(package private)  FromTable getCursorTargetTable()
          Assumes that isCursorUpdatable has been called, and that it is only called for updatable cursors.
 FromList getFromList()
          Return the fromList for this SelectNode.
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.
 boolean getGeneratedForGroupbyClause()
          Return whether or not this SelectNode was generated for a GROUP BY clause.
 GroupByList getGroupByList()
          Return the groupByList for this SelectNode.
 SubqueryList getSelectSubquerys()
          Return the selectSubquerys for this SelectNode.
 ValueNode getWhereClause()
          Return the whereClause for this SelectNode.
 PredicateList getWherePredicates()
          Return the wherePredicates for this SelectNode.
 SubqueryList getWhereSubquerys()
          Return the whereSubquerys for this SelectNode.
(package private)  boolean hasDistinct()
           
 void init(java.lang.Object selectList, java.lang.Object aggregateVector, java.lang.Object fromList, java.lang.Object whereClause, java.lang.Object groupByList)
          Initializer for a SelectNode.
private  boolean isOrderedResult(ResultColumnList resultColumns, ResultSetNode newTopRSN, boolean permuteOrdering)
          Is the result of this node an ordered result set.
(package private)  boolean isUpdatableCursor(DataDictionary dd)
          Determine if this select is updatable or not, for a cursor.
 void makeDistinct()
           
 void markAsForGroupByClause()
          Mark this SelectNode as being generated for a GROUP BY clause.
 void markAsForHavingClause()
          Mark this SelectNode as being generated for a HAVING clause.
 ResultSetNode modifyAccessPaths()
          Modify the access paths according to the choices the optimizer made.
private  void normExpressions()
          Put the expression trees in conjunctive normal form
 ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicateList, double outerRows)
          Optimize this SelectNode.
private  void performTransitiveClosure(int numTables)
          Peform the various types of transitive closure on the where clause.
 ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fl)
          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 pushExpressionsIntoSelect(Predicate predicate)
          Push an expression into this SELECT (and possibly down into one of the tables in the FROM list).
(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 referencesSessionSchema()
          Return true if the node references SESSION schema tables (temporary or permanent)
 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) ?
(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()
           
(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 table.
 java.lang.String toString()
          Convert this object to a String.
(package private)  boolean uniqueSubquery(boolean 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.
 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.ResultSetNode
assignResultSetNumber, bindVTITables, changeAccessPath, closeMethodArgument, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, fillInReferencedTableMap, generateNormalizationResultSet, generateResultSet, genNewRCForInsert, genNormalizeResultSetNode, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getFinalCostEstimate, getMatchingColumn, getNewCostEstimate, getOptimizer, getReferencedTableMap, getResultColumns, getResultSetNumber, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markOrderingDependent, markStatementResultSet, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, projectResultColumns, renameGeneratedResultNames, replaceDefaults, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes
 
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, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, 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

fromList

FromList fromList
List of tables in the FROM clause of this SELECT


targetTable

FromTable targetTable

selectAggregates

java.util.Vector selectAggregates

whereAggregates

java.util.Vector whereAggregates

whereClause

ValueNode whereClause
The ValueNode for the WHERE clause must represent a boolean expression. The binding phase will enforce this - the parser does not have enough information to enforce it in all cases (for example, user methods that return boolean).


originalWhereClause

ValueNode originalWhereClause

groupByList

GroupByList groupByList
List of result columns in GROUP BY clause


orderByList

OrderByList orderByList

orderByQuery

boolean orderByQuery

wherePredicates

PredicateList wherePredicates

selectSubquerys

SubqueryList selectSubquerys

whereSubquerys

SubqueryList whereSubquerys

bindTargetListOnly

private boolean bindTargetListOnly

isDistinct

private boolean isDistinct

orderByAndDistinctMerged

private boolean orderByAndDistinctMerged

generatedForGroupByClause

private boolean generatedForGroupByClause

generatedForHavingClause

private boolean generatedForHavingClause

preJoinFL

private FromList preJoinFL
Constructor Detail

SelectNode

public SelectNode()
Method Detail

init

public void init(java.lang.Object selectList,
                 java.lang.Object aggregateVector,
                 java.lang.Object fromList,
                 java.lang.Object whereClause,
                 java.lang.Object groupByList)
          throws StandardException
Initializer for a SelectNode.

Overrides:
init in class QueryTreeNode
Parameters:
selectList - The result column list for the SELECT statement
aggregateVector - The aggregate vector for this SELECT
fromList - The FROM list for the SELECT statement
whereClause - An expression representing the WHERE clause. It must be a boolean expression, but this is not checked until binding.
groupByList - The GROUP BY list, if any.
Throws:
StandardException - Thrown on error

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

statementToString

public java.lang.String statementToString()

makeDistinct

public void makeDistinct()

clearDistinct

public void clearDistinct()

hasDistinct

boolean hasDistinct()

markAsForGroupByClause

public void markAsForGroupByClause()
Mark this SelectNode as being generated for a GROUP BY clause.

Returns:
Nothing.

getGeneratedForGroupbyClause

public boolean getGeneratedForGroupbyClause()
Return whether or not this SelectNode was generated for a GROUP BY clause.

Returns:
boolean Whether or not this SelectNode was generated for a GROUP BY clause.

markAsForHavingClause

public void markAsForHavingClause()
Mark this SelectNode as being generated for a HAVING clause.

Returns:
Nothing.

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

getFromList

public FromList getFromList()
Return the fromList for this SelectNode.

Overrides:
getFromList in class ResultSetNode
Returns:
FromList The fromList for this SelectNode.

getGroupByList

public GroupByList getGroupByList()
Return the groupByList for this SelectNode.

Returns:
GroupByList The groupByList for this SelectNode.

getWhereClause

public ValueNode getWhereClause()
Return the whereClause for this SelectNode.

Returns:
ValueNode The whereClause for this SelectNode.

getWherePredicates

public PredicateList getWherePredicates()
Return the wherePredicates for this SelectNode.

Returns:
PredicateList The wherePredicates for this SelectNode.

getSelectSubquerys

public SubqueryList getSelectSubquerys()
Return the selectSubquerys for this SelectNode.

Returns:
SubqueryList The selectSubquerys for this SelectNode.

getAggregateVector

public java.util.Vector getAggregateVector(int clause)
Return the specified aggregate vector for this SelectNode.

Parameters:
clause - Which clause to get the aggregate list for
Returns:
aggregateVector The specified aggregate vector for this SelectNode.

getWhereSubquerys

public SubqueryList getWhereSubquerys()
Return the whereSubquerys for this SelectNode.

Returns:
SubqueryList The whereSubquerys for this SelectNode.

bindNonVTITables

public ResultSetNode bindNonVTITables(DataDictionary dataDictionary,
                                      FromList fromListParam)
                               throws StandardException
Bind the tables in this SelectNode. This includes getting their TableDescriptors from the DataDictionary and numbering the FromTables. NOTE: Because this node represents the top of a new query block, we bind both the non VTI and VTI tables under this node in this method call.

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

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.

Overrides:
bindResultColumns in class ResultSetNode
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.

Overrides:
bindResultColumns in class ResultSetNode
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

pushExpressionsIntoSelect

void pushExpressionsIntoSelect(Predicate predicate)
                         throws StandardException
Push an expression into this SELECT (and possibly down into one of the tables in the FROM list). This is useful when trying to push predicates into unflattened views or derived tables.

Parameters:
predicate - The predicate that we attempt to push
Returns:
None
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

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.

Overrides:
getFromTableByName in class ResultSetNode
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

rejectParameters

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

Overrides:
rejectParameters in class ResultSetNode
Returns:
Nothing
Throws:
StandardException - Thrown if a ? parameter found directly under a ResultColumn

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 fl)
                         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 - The number of tables in the DML Statement
gbl - The outer group by list, if any
fl - The from list, if any
Returns:
The generated ProjectRestrictNode atop the original FromTable.
Throws:
StandardException - Thrown on error

performTransitiveClosure

private void performTransitiveClosure(int numTables)
                               throws StandardException
Peform the various types of transitive closure on the where clause. The 2 types are transitive closure on join clauses and on search clauses. Join clauses will be processed first to maximize benefit for search clauses.

Parameters:
numTables - The number of tables in the query
Returns:
None.
Throws:
StandardException - Thrown on error

normExpressions

private void normExpressions()
                      throws StandardException
Put the expression trees in conjunctive normal form

Returns:
None.
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. (ie, not a RowResultSetNode or a UnionNode) o It contains a single table in its FROM list. o It contains no subqueries in the SELECT list. o It does not contain a group by or having clause o It does not contain aggregates. o It is not a DISTINCT.

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

genProjectRestrict

public ResultSetNode genProjectRestrict(int origFromListSize)
                                 throws StandardException
Replace this SelectNode with a ProjectRestrictNode, since it has served its purpose.

Overrides:
genProjectRestrict in class ResultSetNode
Parameters:
origFromListSize - The size of the original FROM list, before generation of join tree.
Returns:
ResultSetNode new ResultSetNode atop the query tree.
Throws:
StandardException - Thrown on error

isOrderedResult

private boolean isOrderedResult(ResultColumnList resultColumns,
                                ResultSetNode newTopRSN,
                                boolean permuteOrdering)
                         throws StandardException
Is the result of this node an ordered result set. An ordered result set means that the results from this node will come in a known sorted order. This means that the data is ordered according to the order of the elements in the RCL. Today, the data is considered ordered if: o The RCL is composed entirely of CRs or ConstantNodes o The underlying tree is ordered on the CRs in the order in which they appear in the RCL, taking equality predicates into account. Future Enhancements: o The prefix will not be required to be in order. (We will need to reorder the RCL and generate a PRN with an RCL in the expected order.)

Returns:
boolean Whether or not this node returns an ordered result set.
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

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

modifyAccessPaths

public ResultSetNode modifyAccessPaths()
                                throws StandardException
Modify the access paths according to the choices the optimizer made.

Overrides:
modifyAccessPaths in class ResultSetNode
Returns:
A QueryTree with the necessary modifications made
Throws:
StandardException - Thrown on error

isUpdatableCursor

boolean isUpdatableCursor(DataDictionary dd)
                    throws StandardException
Determine if this select is updatable or not, for a cursor.

Overrides:
isUpdatableCursor in class ResultSetNode
Throws:
StandardException - Thrown on error

getCursorTargetTable

FromTable getCursorTargetTable()
Assumes that isCursorUpdatable has been called, and that it is only called for updatable cursors.

Overrides:
getCursorTargetTable in class ResultSetNode

referencesTarget

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

Overrides:
referencesTarget in class ResultSetNode
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 table.

Overrides:
subqueryReferencesTarget in class ResultSetNode
Parameters:
name - The table name.
baseTable - Whether or not table is a base table.
Returns:
boolean Whether or not a reference to the table was found.
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

decrementLevel

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.

Specified by:
decrementLevel in class ResultSetNode
Parameters:
decrement - The amount to decrement by.
Returns:
Nothing;

uniqueSubquery

boolean uniqueSubquery(boolean additionalEQ)
                 throws StandardException
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. A uniqueness condition exists when we can guarantee that at most 1 row will qualify in each table in the subquery. This is true if every table in the from list is (a base table and the set of columns from the table that are in equality comparisons with expressions that do not include a column from the same table is a superset of any unique index on the table) or an ExistsBaseTable.

Parameters:
additionalEQ - Whether or not the column returned by this select, if it is a ColumnReference, is in an equality comparison.
Returns:
Whether or not this subquery can be flattened based on a uniqueness condition.
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.

Overrides:
updateTargetLockMode in class ResultSetNode
Returns:
The lock mode
See Also:
TransactionController

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.

referencesSessionSchema

public boolean referencesSessionSchema()
                                throws StandardException
Return true if the node references SESSION schema tables (temporary or permanent)

Overrides:
referencesSessionSchema in class QueryTreeNode
Returns:
true if references SESSION schema tables, else false
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 ResultSetNode
Parameters:
v - the visitor
Throws:
StandardException - on error


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