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

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.TableOperatorNode
All Implemented Interfaces:
Optimizable, Visitable
Direct Known Subclasses:
JoinNode, SetOperatorNode

public abstract class TableOperatorNode
extends FromTable

A TableOperatorNode represents a relational operator like UNION, INTERSECT, JOIN, etc. that takes two tables as parameters and returns a table. The parameters it takes are represented as ResultSetNodes. Currently, all known table operators are binary operators, so there are no subclasses of this node type called "BinaryTableOperatorNode" and "UnaryTableOperatorNode".

Author:
Jeff Lichtman

Field Summary
private  boolean leftModifyAccessPathsDone
           
(package private)  Optimizer leftOptimizer
           
(package private)  ResultSetNode leftResultSet
           
(package private)  boolean nestedInParens
           
private  boolean rightModifyAccessPathsDone
           
(package private)  Optimizer rightOptimizer
           
(package private)  ResultSetNode rightResultSet
           
 
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
TableOperatorNode()
           
 
Method Summary
 Visitable accept(Visitor v)
          Accept a visitor, and call v.visit() on child nodes as necessary.
 void bindExpressions(FromList fromListParam)
          Bind the expressions under this TableOperatorNode.
 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 TableOperatorNode.
 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.
 ResultSetNode bindVTITables(FromList fromListParam)
          Bind the VTI tables in this TableOperatorNode.
(package private)  void decrementLevel(int decrement)
          Decrement (query block) level (0-based) for all of the tables in this ResultSet tree.
 java.lang.String getExposedName()
          Return the exposed name for this table, which is the name that can be used to refer to this table in the rest of the query.
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.
 ResultSetNode getLeftmostResultSet()
           
 ResultSetNode getLeftResultSet()
          Get the leftResultSet from this node.
 boolean getNestedInParens()
          Return whether or not the table operator for this node was nested in parens in the query.
 ResultSetNode getRightResultSet()
          Get the rightResultSet from this node.
 void init(java.lang.Object leftResultSet, java.lang.Object rightResultSet, java.lang.Object tableProperties)
          Initializer for a TableOperatorNode.
(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 needsSpecialRCLBinding()
          apparently something special needs to be done for me....
 ResultSetNode optimize(DataDictionary dataDictionary, PredicateList predicateList, double outerRows)
          Optimize a TableOperatorNode.
protected  ResultSetNode optimizeSource(Optimizer optimizer, ResultSetNode sourceResultSet, PredicateList predList, CostEstimate outerCost)
          Optimize a source result set to this table operator.
 ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList)
          Put a ProjectRestrictNode on top of each FromTable in the FromList.
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
(package private)  void projectResultColumns()
          Find the unreferenced result columns and project them out.
 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)  void replaceDefaults(TableDescriptor ttd, ResultColumnList tcl)
          Replace any DEFAULTs with the associated tree for the default.
 void setLeftmostResultSet(ResultSetNode newLeftResultSet)
           
 void setLevel(int level)
          Set the (query block) level (0-based) for this FromTable.
 void setNestedInParens(boolean nestedInParens)
          Mark whether or not this node is nested in parens.
(package private)  void setReferencedColumns()
          Set the referenced columns in the column list if it may not be correct.
 java.lang.String toString()
          Convert this object to a String.
 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, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, feasibleJoinStrategy, fillInReferencedTableMap, flatten, forUpdate, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCostEstimate, getCurrentAccessPath, getLevel, getName, getNumColumnsReturned, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasTableNumber, init, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, nextAccessPath, optimizeIt, optimizeSubqueries, pullOptPredicates, pushExpressions, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setAllColumnsProjected, setCostEstimate, setHashKeyColumns, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, uniqueJoin
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, assignResultSetNumber, bindTargetExpressions, bindUntypedNullsToResultColumns, changeAccessPath, closeMethodArgument, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, generateNormalizationResultSet, generateResultSet, genNewRCForInsert, genNormalizeResultSetNode, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCostEstimate, getCursorTargetTable, getFinalCostEstimate, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getReferencedTableMap, getResultColumns, getResultSetNumber, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, parseDefault, performMaterialization, pushOrderByList, rejectXMLValues, renameGeneratedResultNames, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes, subqueryReferencesTarget, updateTargetLockMode, verifySelectStarSubquery
 
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, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, 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
 
Methods inherited from interface org.apache.derby.iapi.sql.compile.Optimizable
getDataDictionary, getReferencedTableMap, getResultSetNumber
 

Field Detail

nestedInParens

boolean nestedInParens

leftResultSet

ResultSetNode leftResultSet

rightResultSet

ResultSetNode rightResultSet

leftOptimizer

Optimizer leftOptimizer

rightOptimizer

Optimizer rightOptimizer

leftModifyAccessPathsDone

private boolean leftModifyAccessPathsDone

rightModifyAccessPathsDone

private boolean rightModifyAccessPathsDone
Constructor Detail

TableOperatorNode

public TableOperatorNode()
Method Detail

init

public void init(java.lang.Object leftResultSet,
                 java.lang.Object rightResultSet,
                 java.lang.Object tableProperties)
          throws StandardException
Initializer for a TableOperatorNode.

Overrides:
init in class QueryTreeNode
Parameters:
leftResultSet - The ResultSetNode on the left side of this node
rightResultSet - The ResultSetNode on the right side of this node
tableProperties - Properties list associated with the table
Throws:
StandardException - Thrown on error

modifyAccessPath

public Optimizable modifyAccessPath(JBitSet outerTables)
                             throws StandardException
Description copied from interface: Optimizable
Modify the access path for this Optimizable, as necessary. This includes things like adding a result set to translate from index rows to base rows

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

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)

toString

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

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

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

getLeftResultSet

public ResultSetNode getLeftResultSet()
Get the leftResultSet from this node.

Returns:
ResultSetNode The leftResultSet from this node.

getRightResultSet

public ResultSetNode getRightResultSet()
Get the rightResultSet from this node.

Returns:
ResultSetNode The rightResultSet from this node.

getLeftmostResultSet

public ResultSetNode getLeftmostResultSet()

setLeftmostResultSet

public void setLeftmostResultSet(ResultSetNode newLeftResultSet)

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

getExposedName

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

Overrides:
getExposedName in class FromTable
Returns:
The exposed name for this table.

setNestedInParens

public void setNestedInParens(boolean nestedInParens)
Mark whether or not this node is nested in parens. (Useful to parser since some trees get created left deep and others right deep.)

Parameters:
nestedInParens - Whether or not this node is nested in parens.
Returns:
Nothing.

getNestedInParens

public boolean getNestedInParens()
Return whether or not the table operator for this node was nested in parens in the query. (Useful to parser since some trees get created left deep and others right deep.)

Returns:
boolean Whether or not this node was nested in parens.

bindNonVTITables

public ResultSetNode bindNonVTITables(DataDictionary dataDictionary,
                                      FromList fromListParam)
                               throws StandardException
Bind the non VTI tables in this TableOperatorNode. This means getting their TableDescriptors from the DataDictionary. We will build an unbound RCL for this node. This RCL must be "bound by hand" after the underlying left and right RCLs are bound.

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

bindVTITables

public ResultSetNode bindVTITables(FromList fromListParam)
                            throws StandardException
Bind the VTI tables in this TableOperatorNode. This means getting their TableDescriptors from the DataDictionary. We will build an unbound RCL for this node. This RCL must be "bound by hand" after the underlying left and right RCLs are bound.

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

bindExpressions

public void bindExpressions(FromList fromListParam)
                     throws StandardException
Bind the expressions under this TableOperatorNode. 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

rejectParameters

public void rejectParameters()
                      throws StandardException
Check for (and reject) ? parameters directly under the ResultColumns. This is done for SELECT statements. For TableOperatorNodes, we simply pass the check through to the left and right children.

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

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

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

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 FromTable
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

preprocess

public ResultSetNode preprocess(int numTables,
                                GroupByList gbl,
                                FromList fromList)
                         throws StandardException
Put a ProjectRestrictNode on top of each FromTable in the FromList. ColumnReferences must continue to point to the same ResultColumn, so that ResultColumn must percolate up to the new PRN. However, that ResultColumn will point to a new expression, a VirtualColumnNode, which points to the FromTable and the ResultColumn that is the source for the ColumnReference. (The new PRN will have the original of the ResultColumnList and the ResultColumns from that list. The FromTable will get shallow copies of the ResultColumnList and its ResultColumns. ResultColumn.expression will remain at the FromTable, with the PRN getting a new VirtualColumnNode for each ResultColumn.expression.) We then project out the non-referenced columns. If there are no referenced columns, then the PRN's ResultColumnList will consist of a single ResultColumn whose expression is 1.

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

projectResultColumns

void projectResultColumns()
                    throws StandardException
Find the unreferenced result columns and project them out. This is used in pre-processing joins that are not flattened into the where clause.

Overrides:
projectResultColumns in class ResultSetNode
Throws:
StandardException

setReferencedColumns

void setReferencedColumns()
Set the referenced columns in the column list if it may not be correct.


optimize

public ResultSetNode optimize(DataDictionary dataDictionary,
                              PredicateList predicateList,
                              double outerRows)
                       throws StandardException
Optimize a TableOperatorNode.

Overrides:
optimize in class ResultSetNode
Parameters:
dataDictionary - The DataDictionary to use for optimization
predicateList - The PredicateList to apply.
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
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()

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

optimizeSource

protected ResultSetNode optimizeSource(Optimizer optimizer,
                                       ResultSetNode sourceResultSet,
                                       PredicateList predList,
                                       CostEstimate outerCost)
                                throws StandardException
Optimize a source result set to this table operator.

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.

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

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.

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

needsSpecialRCLBinding

public boolean needsSpecialRCLBinding()
apparently something special needs to be done for me....

Overrides:
needsSpecialRCLBinding in class FromTable

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

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