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

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.SingleChildResultSetNode
                  extended byorg.apache.derby.impl.sql.compile.ProjectRestrictNode
All Implemented Interfaces:
Optimizable, Visitable

public class ProjectRestrictNode
extends SingleChildResultSetNode

A ProjectRestrictNode represents a result set for any of the basic DML operations: SELECT, INSERT, UPDATE, and DELETE. For INSERT with a VALUES clause, restriction 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. NOTE: A ProjectRestrictNode extends FromTable since it can exist in a FromList.

Author:
Jeff Lichtman

Field Summary
private  boolean accessPathConsidered
           
private  boolean accessPathModified
           
(package private)  ResultSetNode childResult
          ResultSetNode under the SingleChildResultSetNode
private  boolean childResultOptimized
           
(package private)  ValueNode constantRestriction
          Constant expressions to be evaluated here.
private  boolean getTableNumberHere
           
protected  boolean hasTrulyTheBestAccessPath
           
private  boolean materialize
           
(package private)  SubqueryList projectSubquerys
          List of subqueries in projection
 ValueNode restriction
          The ValueNode for the restriction to be evaluated here.
 PredicateList restrictionList
          Restriction as a PredicateList
(package private)  SubqueryList restrictSubquerys
          List of subqueries in restriction
 
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
ProjectRestrictNode()
           
 
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.
 ResultSetNode changeAccessPath()
          The optimizer's decision on the access path for a result set may require the generation of extra result sets.
 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.)
 boolean considerSortAvoidancePath()
          Check whether this optimizable's sort avoidance path should be considered.
(package private)  void decrementLevel(int decrement)
          Decrement (query block) level (0-based) for this FromTable.
 ResultSetNode ensurePredicateList(int numTables)
          Ensure that the top of the RSN tree has a PredicateList.
 boolean feasibleJoinStrategy(OptimizablePredicateList predList, Optimizer optimizer)
          Is the current proposed join strategy for this optimizable feasible given the predicate list?
 boolean flattenableInFromSubquery(FromList fromList)
          Evaluate whether or not the subquery in a FromSubquery is flattenable.
 boolean forUpdate()
          Return true if this is the target table of an update
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          For joins, the tree will be (nodes are left out if the clauses are empty): ProjectRestrictResultSet -- for the having and the select list SortResultSet -- for the group by list ProjectRestrictResultSet -- for the where and the select list (if no group or having) the result set for the fromList
private  void generateMinion(ExpressionClassBuilder acb, MethodBuilder mb, boolean genChildResultSet)
          Logic shared by generate() and generateResultSet().
 void generateNOPProjectRestrict()
          Bypass the generation of this No-Op ProjectRestrict, and just generate its child result set.
 void generateResultSet(ExpressionClassBuilder acb, MethodBuilder mb)
          General logic shared by Core compilation.
 AccessPath getBestAccessPath()
          Get the best access path for this Optimizable.
 AccessPath getBestSortAvoidancePath()
          Get the best sort-avoidance path for this Optimizable.
 ResultSetNode getChildResult()
          Return the childResult from this node.
 CostEstimate getCostEstimate()
          Get the CostEstimate for this ProjectRestrictNode.
 AccessPath getCurrentAccessPath()
          Get the current access path under consideration for this Optimizable
 CostEstimate getFinalCostEstimate()
          Get the final CostEstimate for this ProjectRestrictNode.
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.
(package private)  PredicateList getRestrictionList()
          Return the restriction list from this node.
 int getTableNumber()
          Get this Optimizable's table number
 AccessPath getTrulyTheBestAccessPath()
          Get the best access path overall for this Optimizable.
(package private)  java.lang.String getUserSpecifiedJoinStrategy()
          Return the user specified join strategy, if any for this table.
 void init(java.lang.Object childResult, java.lang.Object tableProperties)
          Initialilzer for a SingleChildResultSetNode.
 void init(java.lang.Object childResult, java.lang.Object projection, java.lang.Object restriction, java.lang.Object restrictionList, java.lang.Object projectSubquerys, java.lang.Object restrictSubquerys, java.lang.Object tableProperties)
          Initializer for a ProjectRestrictNode.
 void initAccessPaths(Optimizer optimizer)
          Init the access paths for this optimizable.
 boolean isMaterializable()
          Tell whether this Optimizable is materializable
 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.
 boolean legalJoinOrder(JBitSet assignedTableMap)
          Can this Optimizable appear at the current location in the join order.
(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.
 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.
 boolean nextAccessPath(Optimizer optimizer, OptimizablePredicateList predList, RowOrdering rowOrdering)
          Choose the next access path to evaluate for this Optimizable.
(package private)  boolean nopProjectRestrict()
          Determine whether this ProjectRestrict does anything.
 ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicates, double outerRows)
          Optimize this ProjectRestrictNode.
 CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering)
          Choose the best access path for this Optimizable.
 ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList)
          Put a ProjectRestrictNode on top of each FromTable in the FromList.
(package private)  void printRememberingBestAccessPath(int planType, AccessPath bestPath)
           
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 void pullOptPredicates(OptimizablePredicateList optimizablePredicates)
          Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.
 void pushExpressions(PredicateList predicateList)
          Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map.
 boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)
          Push an OptimizablePredicate down, if this node accepts it.
 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.
protected  boolean reflectionNeededForProjection()
          Determine whether we need to do reflection in order to do the projection.
 void rememberAsBest(int planType)
          Remember the current access path as the best one (so far).
 void rememberSortAvoidancePath()
          Mark this optimizable so that its sort avoidance path will be considered.
(package private)  void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl)
          Replace any DEFAULTs with the associated tree for the default.
private  Optimizable replaceWithHashTableNode()
          This method creates a HashTableNode between the PRN and it's child when the optimizer chooses hash join on an arbitrary (non-FBT) result set tree.
(package private)  void setChildResult(ResultSetNode childResult)
          Set the childResult for this node.
 void setLevel(int level)
          Set the (query block) level (0-based) for this FromTable.
 void setRefActionInfo(long fkIndexConglomId, int[] fkColArray, java.lang.String parentResultSetId, boolean dependentScan)
          set the Information gathered from the parent table that is required to peform a referential action on dependent table.
 void startOptimizing(Optimizer optimizer, RowOrdering rowOrdering)
          Begin the optimization process for this Optimizable.
(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.
 double uniqueJoin(OptimizablePredicateList predList)
          Does this optimizable have a uniqueness condition on the given predicate list, and if so, how many unique keys will be returned per scan.
 int updateTargetLockMode()
          Get the lock mode for the target of an update statement (a delete or update).
 void verifyProperties(DataDictionary dDictionary)
          Verify that the Properties list with optimizer overrides, if specified, is valid
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
areAllColumnsProjected, assignCostEstimate, canBeOrdered, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, fillInReferencedTableMap, flatten, getBaseTableName, getCostEstimate, getExposedName, getLevel, getName, getNumColumnsReturned, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, hashKeyColumns, hasTableNumber, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isOneRowScan, isTargetTable, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsage, needsSpecialRCLBinding, optimizeSubqueries, rememberJoinStrategyAsBest, resetJoinStrategies, setAllColumnsProjected, setCostEstimate, setHashKeyColumns, setProperties, setTableNumber, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, toString, transformOuterJoins
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
assignResultSetNumber, bindExpressions, bindExpressionsWithTables, bindNonVTITables, bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, bindVTITables, closeMethodArgument, columnTypesAndLengthsMatch, enhanceRCLForInsert, generateNormalizationResultSet, genNewRCForInsert, genNormalizeResultSetNode, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getReferencedTableMap, getResultColumns, getResultSetNumber, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markStatementResultSet, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, projectResultColumns, pushOrderByList, rejectParameters, renameGeneratedResultNames, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes, verifySelectStarSubquery
 
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, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, setBeginOffset, setContextManager, setEndOffset, setNodeType, 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

restriction

public ValueNode restriction
The ValueNode for the restriction to be evaluated here.


constantRestriction

ValueNode constantRestriction
Constant expressions to be evaluated here.


restrictionList

public PredicateList restrictionList
Restriction as a PredicateList


projectSubquerys

SubqueryList projectSubquerys
List of subqueries in projection


restrictSubquerys

SubqueryList restrictSubquerys
List of subqueries in restriction


accessPathModified

private boolean accessPathModified

accessPathConsidered

private boolean accessPathConsidered

childResultOptimized

private boolean childResultOptimized

materialize

private boolean materialize

getTableNumberHere

private boolean getTableNumberHere

childResult

ResultSetNode childResult
ResultSetNode under the SingleChildResultSetNode


hasTrulyTheBestAccessPath

protected boolean hasTrulyTheBestAccessPath
Constructor Detail

ProjectRestrictNode

public ProjectRestrictNode()
Method Detail

init

public void init(java.lang.Object childResult,
                 java.lang.Object projection,
                 java.lang.Object restriction,
                 java.lang.Object restrictionList,
                 java.lang.Object projectSubquerys,
                 java.lang.Object restrictSubquerys,
                 java.lang.Object tableProperties)
Initializer for a ProjectRestrictNode.

Overrides:
init in class QueryTreeNode
Parameters:
childResult - The child ResultSetNode
projection - The result column list for the projection
restriction - An expression representing the restriction to be evaluated here.
restrictionList - Restriction as a PredicateList
projectSubquerys - List of subqueries in the projection
restrictSubquerys - List of subqueries in the restriction
tableProperties - Properties list associated with the table

nextAccessPath

public boolean nextAccessPath(Optimizer optimizer,
                              OptimizablePredicateList predList,
                              RowOrdering rowOrdering)
                       throws StandardException
Description copied from interface: Optimizable
Choose the next access path to evaluate for this Optimizable.

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

rememberAsBest

public void rememberAsBest(int planType)
                    throws StandardException
Description copied from interface: Optimizable
Remember the current access path as the best one (so far).

Specified by:
rememberAsBest in interface Optimizable
Overrides:
rememberAsBest in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.rememberAsBest(int)

printRememberingBestAccessPath

void printRememberingBestAccessPath(int planType,
                                    AccessPath bestPath)

startOptimizing

public void startOptimizing(Optimizer optimizer,
                            RowOrdering rowOrdering)
Description copied from interface: Optimizable
Begin the optimization process for this Optimizable. This can be called many times for an Optimizable while optimizing a query - it will typically be called every time the Optimizable is placed in a potential join order.

Specified by:
startOptimizing in interface Optimizable
Overrides:
startOptimizing in class FromTable
See Also:
Optimizable.startOptimizing(org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.RowOrdering)

getTableNumber

public int getTableNumber()
Description copied from interface: Optimizable
Get this Optimizable's table number

Specified by:
getTableNumber in interface Optimizable
Overrides:
getTableNumber in class FromTable
See Also:
Optimizable.getTableNumber()

optimizeIt

public CostEstimate optimizeIt(Optimizer optimizer,
                               OptimizablePredicateList predList,
                               CostEstimate outerCost,
                               RowOrdering rowOrdering)
                        throws StandardException
Description copied from interface: Optimizable
Choose the best access path for this Optimizable.

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

feasibleJoinStrategy

public boolean feasibleJoinStrategy(OptimizablePredicateList predList,
                                    Optimizer optimizer)
                             throws StandardException
Description copied from interface: Optimizable
Is the current proposed join strategy for this optimizable feasible given the predicate list?

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

getCurrentAccessPath

public AccessPath getCurrentAccessPath()
Description copied from interface: Optimizable
Get the current access path under consideration for this Optimizable

Specified by:
getCurrentAccessPath in interface Optimizable
Overrides:
getCurrentAccessPath in class FromTable
See Also:
Optimizable.getCurrentAccessPath()

getBestAccessPath

public AccessPath getBestAccessPath()
Description copied from interface: Optimizable
Get the best access path for this Optimizable.

Specified by:
getBestAccessPath in interface Optimizable
Overrides:
getBestAccessPath in class FromTable
See Also:
Optimizable.getBestAccessPath()

getBestSortAvoidancePath

public AccessPath getBestSortAvoidancePath()
Description copied from interface: Optimizable
Get the best sort-avoidance path for this Optimizable.

Specified by:
getBestSortAvoidancePath in interface Optimizable
Overrides:
getBestSortAvoidancePath in class FromTable
See Also:
Optimizable.getBestSortAvoidancePath()

getTrulyTheBestAccessPath

public AccessPath getTrulyTheBestAccessPath()
Description copied from interface: Optimizable
Get the best access path overall for this Optimizable.

Specified by:
getTrulyTheBestAccessPath in interface Optimizable
Overrides:
getTrulyTheBestAccessPath in class SingleChildResultSetNode
See Also:
Optimizable.getTrulyTheBestAccessPath()

rememberSortAvoidancePath

public void rememberSortAvoidancePath()
Description copied from interface: Optimizable
Mark this optimizable so that its sort avoidance path will be considered.

Specified by:
rememberSortAvoidancePath in interface Optimizable
Overrides:
rememberSortAvoidancePath in class FromTable
See Also:
Optimizable.rememberSortAvoidancePath()

considerSortAvoidancePath

public boolean considerSortAvoidancePath()
Description copied from interface: Optimizable
Check whether this optimizable's sort avoidance path should be considered.

Specified by:
considerSortAvoidancePath in interface Optimizable
Overrides:
considerSortAvoidancePath in class FromTable
See Also:
Optimizable.considerSortAvoidancePath()

pushOptPredicate

public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate)
                         throws StandardException
Description copied from interface: Optimizable
Push an OptimizablePredicate down, if this node accepts it.

Specified by:
pushOptPredicate in interface Optimizable
Overrides:
pushOptPredicate in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.pushOptPredicate(org.apache.derby.iapi.sql.compile.OptimizablePredicate)

pullOptPredicates

public void pullOptPredicates(OptimizablePredicateList optimizablePredicates)
                       throws StandardException
Description copied from interface: Optimizable
Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.

Specified by:
pullOptPredicates in interface Optimizable
Overrides:
pullOptPredicates in class SingleChildResultSetNode
Throws:
StandardException - Thrown on error
See Also:
Optimizable.pullOptPredicates(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)

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)

replaceWithHashTableNode

private Optimizable replaceWithHashTableNode()
                                      throws StandardException
This method creates a HashTableNode between the PRN and it's child when the optimizer chooses hash join on an arbitrary (non-FBT) result set tree. We divide up the restriction list into 3 parts and distribute those parts as described below.

Returns:
The new (same) top of our result set tree.
Throws:
StandardException - Thrown on error

verifyProperties

public void verifyProperties(DataDictionary dDictionary)
                      throws StandardException
Description copied from interface: Optimizable
Verify that the Properties list with optimizer overrides, if specified, is valid

Specified by:
verifyProperties in interface Optimizable
Overrides:
verifyProperties in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.verifyProperties(org.apache.derby.iapi.sql.dictionary.DataDictionary)

legalJoinOrder

public boolean legalJoinOrder(JBitSet assignedTableMap)
Description copied from interface: Optimizable
Can this Optimizable appear at the current location in the join order. In other words, have the Optimizable's dependencies been satisfied?

Specified by:
legalJoinOrder in interface Optimizable
Overrides:
legalJoinOrder in class FromTable
See Also:
Optimizable.legalJoinOrder(org.apache.derby.iapi.util.JBitSet)

isMaterializable

public boolean isMaterializable()
                         throws StandardException
Description copied from interface: Optimizable
Tell whether this Optimizable is materializable

Specified by:
isMaterializable in interface Optimizable
Overrides:
isMaterializable in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.isMaterializable()

uniqueJoin

public double uniqueJoin(OptimizablePredicateList predList)
                  throws StandardException
Description copied from interface: Optimizable
Does this optimizable have a uniqueness condition on the given predicate list, and if so, how many unique keys will be returned per scan.

Specified by:
uniqueJoin in interface Optimizable
Overrides:
uniqueJoin in class FromTable
Throws:
StandardException - Thrown on error
See Also:
Optimizable.uniqueJoin(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)

getRestrictionList

PredicateList getRestrictionList()
Return the restriction list from this node.

Returns:
The restriction list from this node.

getUserSpecifiedJoinStrategy

java.lang.String getUserSpecifiedJoinStrategy()
Return the user specified join strategy, if any for this table.

Overrides:
getUserSpecifiedJoinStrategy in class FromTable
Returns:
The user specified join strategy, if any for this table.

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

pushExpressions

public void pushExpressions(PredicateList predicateList)
                     throws StandardException
Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map. RESOLVE - This means only pushing down single table expressions to ProjectRestrictNodes today. Once we have a better understanding of how the optimizer will work, we can push down join clauses.

Overrides:
pushExpressions in class SingleChildResultSetNode
Parameters:
predicateList - The PredicateList.
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 SingleChildResultSetNode
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. 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.

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

ensurePredicateList

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

Overrides:
ensurePredicateList in class SingleChildResultSetNode
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 predicates,
                              double outerRows)
                       throws StandardException
Optimize this ProjectRestrictNode.

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

getCostEstimate

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

Overrides:
getCostEstimate in class ResultSetNode
Returns:
The CostEstimate for this ProjectRestrictNode, which is the cost estimate for the child node.

getFinalCostEstimate

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

Overrides:
getFinalCostEstimate in class SingleChildResultSetNode
Returns:
The final CostEstimate for this ProjectRestrictNode, which is the final cost estimate for the child node.

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
For joins, the tree will be (nodes are left out if the clauses are empty): ProjectRestrictResultSet -- for the having and the select list SortResultSet -- for the group by list ProjectRestrictResultSet -- for the where and the select list (if no group or having) the result set for the fromList

Overrides:
generate in class QueryTreeNode
Parameters:
acb - The ActivationClassBuilder for the class being built
mb - The method for the generated code to go into
Throws:
StandardException - Thrown on error

generateResultSet

public void generateResultSet(ExpressionClassBuilder acb,
                              MethodBuilder mb)
                       throws StandardException
General logic shared by Core compilation.

Overrides:
generateResultSet in class ResultSetNode
Parameters:
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

generateMinion

private void generateMinion(ExpressionClassBuilder acb,
                            MethodBuilder mb,
                            boolean genChildResultSet)
                     throws StandardException
Logic shared by generate() and generateResultSet().

Parameters:
mb - The method the expression will go into
Returns:
The compiled Expression
Throws:
StandardException - Thrown on error

nopProjectRestrict

boolean nopProjectRestrict()
Determine whether this ProjectRestrict does anything. If it doesn't filter out any rows or columns, it's a No-Op.

Returns:
true if this ProjectRestrict is a No-Op.

generateNOPProjectRestrict

public void generateNOPProjectRestrict()
                                throws StandardException
Bypass the generation of this No-Op ProjectRestrict, and just generate its child result set.

Throws:
StandardException - Thrown 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.)

Overrides:
considerMaterialization in class ResultSetNode
Returns:
Top of the new/same ResultSet tree.
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 SingleChildResultSetNode
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

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 SingleChildResultSetNode
Returns:
The lock mode

isPossibleDistinctScan

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

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

Overrides:
markForDistinctScan in class ResultSetNode
Returns:
Nothing.

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 SingleChildResultSetNode
Parameters:
v - the visitor
Throws:
StandardException - on error

setRefActionInfo

public void setRefActionInfo(long fkIndexConglomId,
                             int[] fkColArray,
                             java.lang.String parentResultSetId,
                             boolean dependentScan)
set the Information gathered from the parent table that is required to peform a referential action on dependent table.

Overrides:
setRefActionInfo in class QueryTreeNode
Returns:
Nothing.

init

public void init(java.lang.Object childResult,
                 java.lang.Object tableProperties)
Initialilzer for a SingleChildResultSetNode.

Overrides:
init in class FromTable
Parameters:
childResult - The child ResultSetNode
tableProperties - Properties list associated with the table

getChildResult

public ResultSetNode getChildResult()
Return the childResult from this node.

Returns:
ResultSetNode The childResult from this node.

setChildResult

void setChildResult(ResultSetNode childResult)
Set the childResult for this node.

Parameters:
childResult - The new childResult for this node.
Returns:
Nothing.

forUpdate

public boolean forUpdate()
Description copied from interface: Optimizable
Return true if this is the target table of an update

Specified by:
forUpdate in interface Optimizable
Overrides:
forUpdate in class FromTable
See Also:
Optimizable.forUpdate()

initAccessPaths

public void initAccessPaths(Optimizer optimizer)
Description copied from interface: Optimizable
Init the access paths for this optimizable.

Specified by:
initAccessPaths in interface Optimizable
Overrides:
initAccessPaths in class FromTable
See Also:
Optimizable.initAccessPaths(org.apache.derby.iapi.sql.compile.Optimizer)

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

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

setLevel

public void setLevel(int level)
Set the (query block) level (0-based) for this FromTable.

Overrides:
setLevel in class FromTable
Parameters:
level - The query block level for this FromTable.
Returns:
Nothing

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.

Overrides:
subqueryReferencesTarget in class ResultSetNode
Parameters:
name - The table name.
baseTable - Whether or not the name is for a base table.
Returns:
boolean Whether or not a reference to the table was found.
Throws:
StandardException - Thrown on error

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

changeAccessPath

public ResultSetNode changeAccessPath()
                               throws StandardException
Description copied from class: ResultSetNode
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.

Overrides:
changeAccessPath in class ResultSetNode
Returns:
A ResultSetNode tree modified to do any extra processing for the chosen access path
Throws:
StandardException - Thrown on error
See Also:
ResultSetNode.changeAccessPath()

decrementLevel

void decrementLevel(int decrement)
Decrement (query block) level (0-based) for this FromTable. This is useful when flattening a subquery.

Overrides:
decrementLevel in class FromTable
Parameters:
decrement - The amount to decrement by.

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.

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

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.

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

Overrides:
isNotExists in class ResultSetNode
Returns:
Whether or not the underlying ResultSet tree is for a NOT EXISTS.

reflectionNeededForProjection

protected boolean reflectionNeededForProjection()
Determine whether we need to do reflection in order to do the projection. Reflection is only needed if there is at least 1 column which is not simply selecting the source column.

Returns:
Whether or not we need to do reflection in order to do the projection.

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

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.


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