Class FromTable
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.ResultSetNode
-
- org.apache.derby.impl.sql.compile.FromTable
-
- All Implemented Interfaces:
Optimizable
,Visitable
- Direct Known Subclasses:
CurrentOfNode
,FromBaseTable
,FromSubquery
,FromVTI
,IndexToBaseRowNode
,RowResultSetNode
,SingleChildResultSetNode
,TableOperatorNode
abstract class FromTable extends ResultSetNode implements Optimizable
A FromTable represents a table in the FROM clause of a DML statement. It can be either a base table, a subquery or a project restrict.- See Also:
FromBaseTable
,FromSubquery
,ProjectRestrictNode
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
ResultSetNode.QueryExpressionClauses
-
-
Field Summary
Fields Modifier and Type Field Description private int
_mergeTableID
for resolving column references in MERGE statements in tough casesprotected static short
ADD_PLAN
(package private) AccessPathImpl
bestAccessPath
protected CostEstimate
bestCostEstimate
private java.util.HashMap<java.lang.Object,AccessPathImpl>
bestPlanMap
Set of object->trulyTheBestAccessPath mappings used to keep track of which of this Optimizable's "trulyTheBestAccessPath" was the best with respect to a specific outer query or ancestor node.(package private) AccessPathImpl
bestSortAvoidancePath
private boolean
considerSortAvoidancePath
(package private) java.lang.String
correlationName
(package private) TableName
corrTableName
(package private) AccessPathImpl
currentAccessPath
(package private) int[]
hashKeyColumns
(package private) int
initialCapacity
private int
joinStrategyNumber
(package private) int
level
protected static short
LOAD_PLAN
(package private) float
loadFactor
(package private) int
maxCapacity
protected TableName
origTableName
the original unbound table nameprivate double
perRowUsage
protected static short
REMOVE_PLAN
Operations that can be performed on bestPlanMap.(package private) int
tableNumber
(package private) java.util.Properties
tableProperties
(package private) AccessPathImpl
trulyTheBestAccessPath
protected java.lang.String
userSpecifiedJoinStrategy
-
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description FromTable(java.lang.String correlationName, java.util.Properties tableProperties, ContextManager cm)
Constructor for a table in a FROM list.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
acceptChildren(Visitor v)
Accept the visitor for all visitable children of this node.protected void
assignCostEstimate(CostEstimate newCostEstimate)
Assign the cost estimate in this node to the given cost estimate.protected boolean
canBeOrdered()
Most Optimizables cannot be ordered(package private) boolean
columnsAreUpdatable()
Return true if some columns in this table are updatable.boolean
considerSortAvoidancePath()
Check whether this optimizable's sort avoidance path should be considered.int
convertAbsoluteToRelativeColumnPosition(int absolutePosition)
Convert an absolute to a relative 0-based column position.protected boolean
cursorTargetTable()
Is this a table that has a FOR UPDATE clause.(package private) void
decrementLevel(int decrement)
Decrement (query block) level (0-based) for this FromTable.CostEstimate
estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering)
Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate.boolean
feasibleJoinStrategy(OptimizablePredicateList predList, Optimizer optimizer)
Is the current proposed join strategy for this optimizable feasible given the predicate list?(package private) void
fillInReferencedTableMap(JBitSet passedMap)
Fill the referencedTableMap with this ResultSetNode.(package private) FromList
flatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause)
Flatten this FromTable into the outer query block.boolean
forUpdate()
Return true if this is the target table of an updatejava.lang.String
getBaseTableName()
Get the table name of this Optimizable.AccessPath
getBestAccessPath()
Get the best access path for this Optimizable.AccessPath
getBestSortAvoidancePath()
Get the best sort-avoidance path for this Optimizable.java.lang.String
getCorrelationName()
Get this table's correlation name, if any.protected CostEstimate
getCostEstimate(Optimizer optimizer)
AccessPath
getCurrentAccessPath()
Get the current access path under consideration for this Optimizable(package private) java.lang.String
getExposedName()
Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.(package private) CostEstimate
getFinalCostEstimate()
Get the final CostEstimate for this FromTable.(package private) 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) int
getLevel()
Get the (query block) level (0-based) for this FromTable.(package private) int
getMergeTableID()
get the merge table idjava.lang.String
getName()
Get the (exposed) name of this Optimizableint
getNumColumnsReturned()
Get the number of the number of columns returned by this Optimizable.(package private) TableName
getOrigTableName()
Gets the original or unbound table name for this FromTable.private double
getPerRowUsage()
java.util.Properties
getProperties()
Get the Properties list, if any, associated with this optimizable.(package private) ResultColumnList
getResultColumnsForList(TableName allTableName, ResultColumnList inputRcl, TableName tableName)
Return a ResultColumnList with all of the columns in this table.(package private) SchemaDescriptor
getSchemaDescriptor()
Get a schema descriptor for the given table.(package private) SchemaDescriptor
getSchemaDescriptor(TableName tableName)
Get a schema descriptor for the given table.protected CostEstimate
getScratchCostEstimate(Optimizer optimizer)
TableDescriptor
getTableDescriptor()
Get the table descriptor for this table (if any).(package private) TableName
getTableName()
Return a TableName node representing this FromTable.int
getTableNumber()
Get this Optimizable's table numberAccessPath
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.int[]
hashKeyColumns()
Return the hash key column numbers, for hash join strategyboolean
hasLargeObjectColumns()
Check if any columns containing large objects (BLOBs or CLOBs) are referenced in this table.boolean
hasTableNumber()
Return true if this Optimizable has a table numbervoid
initAccessPaths(Optimizer optimizer)
Init the access paths for this optimizable.int
initialCapacity()
Return the initial capacity of the hash table, for hash join strategyboolean
isBaseTable()
Tell whether this Optimizable represents a base tableboolean
isCoveringIndex(ConglomerateDescriptor cd)
Return whether or not this is a covering index.(package private) boolean
isFlattenableJoinNode()
Is this FromTable a JoinNode which can be flattened into the parents FromList.(package private) void
isJoinColumnForRightOuterJoin(ResultColumn rc)
No-op in FromTable.boolean
isMaterializable()
Tell whether this Optimizable is materializableboolean
isOneRowScan()
Will the optimizable return at most 1 row per scan?boolean
isTargetTable()
Is the optimizable the target table of an update or delete?boolean
legalJoinOrder(JBitSet assignedTableMap)
Can this Optimizable appear at the current location in the join order.float
loadFactor()
Return the load factor of the hash table, for hash join strategy(package private) boolean
LOJ_reorderable(int numTables)
no LOJ reordering for this FromTable.protected void
markUpdatableByCursor(java.util.List<java.lang.String> updateColumns)
Mark as updatable all the columns in the result column list of this FromBaseTable that match the columns in the given update column list.int
maxCapacity(JoinStrategy joinStrategy, int maxMemoryPerTable)
Return the maximum capacity of the hash table, for hash join strategyboolean
memoryUsageOK(double rowCount, int maxMemoryPerTable)
Optimizable
modifyAccessPath(JBitSet outerTables)
Modify the access path for this Optimizable, as necessary.(package private) boolean
needsSpecialRCLBinding()
boolean
nextAccessPath(Optimizer optimizer, OptimizablePredicateList predList, RowOrdering rowOrdering)
Choose the next access path to evaluate for this Optimizable.CostEstimate
optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering)
Choose the best access path for this Optimizable.(package private) void
optimizeSubqueries(DataDictionary dd, double rowCount)
Optimize any subqueries that haven't been optimized any where else.void
pullOptPredicates(OptimizablePredicateList optimizablePredicates)
Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.(package private) 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.void
rememberAsBest(int planType, Optimizer optimizer)
Remember the current access path as the best one (so far).void
rememberJoinStrategyAsBest(AccessPath ap)
Remember the current join strategy as the best one so far in this join order.void
rememberSortAvoidancePath()
Mark this optimizable so that its sort avoidance path will be considered.protected void
resetJoinStrategies(Optimizer optimizer)
This method is called when this table is placed in a potential join order, or when a new conglomerate is being considered.protected void
setCostEstimateCost(CostEstimate newCostEstimate)
Set the cost estimate in this node to the given cost estimate.void
setHashKeyColumns(int[] columnNumbers)
Set the hash key column numbers, for hash join strategy(package private) void
setLevel(int level)
Set the (query block) level (0-based) for this FromTable.(package private) void
setMergeTableID(int mergeTableID)
set the merge table id(package private) void
setOrigTableName(TableName tableName)
Sets the original or unbound table name for this FromTable.void
setProperties(java.util.Properties tableProperties)
Set the Properties list for this optimizalbe.(package private) void
setTableNumber(int tableNumber)
Set the table # for this table.void
startOptimizing(Optimizer optimizer, RowOrdering rowOrdering)
Begin the optimization process for this Optimizable.boolean
supportsMultipleInstantiations()
Tell whether this Optimizable can be instantiated multiple timesprotected void
tellRowOrderingAboutConstantColumns(RowOrdering rowOrdering, OptimizablePredicateList predList)
Tell the given RowOrdering about any columns that are constant due to their being equality comparisons with constant expressions.java.lang.String
toString()
Convert this object to a String.(package private) FromTable
transformOuterJoins(ValueNode predicateTree, int numTables)
Transform any Outer Join into an Inner Join where applicable.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.void
updateBestPlanMap(short action, java.lang.Object planKey)
When remembering "truly the best" access path for an Optimizable, we have to keep track of which OptimizerImpl the "truly the best" access is for.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.ResultSetNode
addNewPredicate, adjustForSortElimination, adjustForSortElimination, assignResultSetNumber, bindExpressions, bindExpressionsWithTables, bindNonVTITables, bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, bindVTITables, changeAccessPath, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCandidateFinalCostEstimate, getCostEstimate, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, getScratchCostEstimate, isCursorTargetTable, isInsertSource, isNotExists, isOneRowResultSet, isOrderedOn, isPossibleDistinctScan, isStatementResultSet, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, optimize, parseDefault, performMaterialization, preprocess, printQueryExpressionSuffixClauses, printSubNodes, projectResultColumns, pushOffsetFetchFirst, pushOrderByList, pushQueryExpressionSuffix, referencesTarget, rejectParameters, rejectXMLValues, renameGeneratedResultNames, replaceOrForbidDefaults, returnsAtMostOneRow, setCandidateFinalCostEstimate, setCostEstimate, setCursorTargetTable, setInsertSource, setOptimizer, setReferencedTableMap, setResultColumns, setResultSetNumber, setResultToBooleanTrueNode, setScratchCostEstimate, setTableConstructorTypes, subqueryReferencesTarget, updateTargetLockMode, verifySelectStarSubquery
-
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, 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, getOptimizerTracer, getReferencedTableMap, getResultSetNumber, optimizerTracingIsOn
-
Methods inherited from interface org.apache.derby.iapi.sql.compile.Visitable
accept, addTag, taggedWith
-
-
-
-
Field Detail
-
tableProperties
java.util.Properties tableProperties
-
correlationName
java.lang.String correlationName
-
corrTableName
TableName corrTableName
-
tableNumber
int tableNumber
-
level
int level
-
hashKeyColumns
int[] hashKeyColumns
-
initialCapacity
int initialCapacity
-
loadFactor
float loadFactor
-
maxCapacity
int maxCapacity
-
currentAccessPath
AccessPathImpl currentAccessPath
-
bestAccessPath
AccessPathImpl bestAccessPath
-
bestSortAvoidancePath
AccessPathImpl bestSortAvoidancePath
-
trulyTheBestAccessPath
AccessPathImpl trulyTheBestAccessPath
-
joinStrategyNumber
private int joinStrategyNumber
-
userSpecifiedJoinStrategy
protected java.lang.String userSpecifiedJoinStrategy
-
bestCostEstimate
protected CostEstimate bestCostEstimate
-
perRowUsage
private double perRowUsage
-
considerSortAvoidancePath
private boolean considerSortAvoidancePath
-
bestPlanMap
private java.util.HashMap<java.lang.Object,AccessPathImpl> bestPlanMap
Set of object->trulyTheBestAccessPath mappings used to keep track of which of this Optimizable's "trulyTheBestAccessPath" was the best with respect to a specific outer query or ancestor node. In the case of an outer query, the object key will be an instance of OptimizerImpl. In the case of an ancestor node, the object key will be that node itself. Each ancestor node or outer query could potentially have a different idea of what this Optimizable's "best access path" is, so we have to keep track of them all.
-
REMOVE_PLAN
protected static final short REMOVE_PLAN
Operations that can be performed on bestPlanMap.- See Also:
- Constant Field Values
-
ADD_PLAN
protected static final short ADD_PLAN
- See Also:
- Constant Field Values
-
LOAD_PLAN
protected static final short LOAD_PLAN
- See Also:
- Constant Field Values
-
origTableName
protected TableName origTableName
the original unbound table name
-
_mergeTableID
private int _mergeTableID
for resolving column references in MERGE statements in tough cases
-
-
Constructor Detail
-
FromTable
FromTable(java.lang.String correlationName, java.util.Properties tableProperties, ContextManager cm)
Constructor for a table in a FROM list.- Parameters:
correlationName
- The correlation nametableProperties
- Properties list associated with the tablecm
- The context manager
-
-
Method Detail
-
getCorrelationName
public java.lang.String getCorrelationName()
Get this table's correlation name, if any.
-
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 interfaceOptimizable
- Parameters:
optimizer
- Optimizer to use.predList
- The predicate list to optimize againstouterCost
- The CostEstimate for the outer tables in the join order, telling how many times this Optimizable will be scanned.rowOrdering
- The row ordering for all the tables in the join order, including this one.- Returns:
- The optimizer's estimated cost of the best access path.
- 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)
-
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 interfaceOptimizable
- Parameters:
optimizer
- Optimizer to use.predList
- The predicate list for this optimizable. The optimizer always passes null, and it is up to the optimizable object to pass along its own predicate list, if appropriate, when delegating this method.rowOrdering
- The row ordering for all the outer tables in the join order. This method will add the ordering of the next access path to the given RowOrdering.- Returns:
- true means another access path was chosen, false means no more access paths to evaluate.
- 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)
-
canBeOrdered
protected boolean canBeOrdered()
Most Optimizables cannot be ordered
-
getCurrentAccessPath
public AccessPath getCurrentAccessPath()
Description copied from interface:Optimizable
Get the current access path under consideration for this Optimizable- Specified by:
getCurrentAccessPath
in interfaceOptimizable
- 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 interfaceOptimizable
- 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 interfaceOptimizable
- 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 interfaceOptimizable
- 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 interfaceOptimizable
- 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 interfaceOptimizable
- See Also:
Optimizable.considerSortAvoidancePath()
-
rememberJoinStrategyAsBest
public void rememberJoinStrategyAsBest(AccessPath ap)
Description copied from interface:Optimizable
Remember the current join strategy as the best one so far in this join order.- Specified by:
rememberJoinStrategyAsBest
in interfaceOptimizable
- See Also:
Optimizable.rememberJoinStrategyAsBest(org.apache.derby.iapi.sql.compile.AccessPath)
-
getTableDescriptor
public TableDescriptor getTableDescriptor()
Description copied from interface:Optimizable
Get the table descriptor for this table (if any). Only base tables have table descriptors - for the rest of the optimizables, this method returns null.- Specified by:
getTableDescriptor
in interfaceOptimizable
- See Also:
Optimizable.getTableDescriptor()
-
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 interfaceOptimizable
- Parameters:
optimizablePredicate
- OptimizablePredicate to push down.- Returns:
- Whether or not the predicate was pushed down.
- 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 interfaceOptimizable
- Parameters:
optimizablePredicates
- The list to put the pulled predicates in.- 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 interfaceOptimizable
- Parameters:
outerTables
- Bit map of the tables that are outer to this one in the join order.- Returns:
- The (potentially new) Optimizable at the top of the tree.
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.modifyAccessPath(org.apache.derby.iapi.util.JBitSet)
-
isCoveringIndex
public boolean isCoveringIndex(ConglomerateDescriptor cd) throws StandardException
Description copied from interface:Optimizable
Return whether or not this is a covering index. We expect to call this during generation, after access path selection is complete.- Specified by:
isCoveringIndex
in interfaceOptimizable
- Parameters:
cd
- ConglomerateDesriptor for index to consider- Returns:
- boolean Whether or not this is a covering index.
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.isCoveringIndex(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)
-
getProperties
public java.util.Properties getProperties()
Description copied from interface:Optimizable
Get the Properties list, if any, associated with this optimizable.- Specified by:
getProperties
in interfaceOptimizable
- Returns:
- The Properties list, if any, associated with this optimizable.
- See Also:
Optimizable.getProperties()
-
setProperties
public void setProperties(java.util.Properties tableProperties)
Description copied from interface:Optimizable
Set the Properties list for this optimizalbe.- Specified by:
setProperties
in interfaceOptimizable
- Parameters:
tableProperties
- The Properties list for this optimizable.- See Also:
Optimizable.setProperties(java.util.Properties)
-
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 interfaceOptimizable
- Parameters:
dDictionary
- The DataDictionary to use.- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.verifyProperties(org.apache.derby.iapi.sql.dictionary.DataDictionary)
-
getName
public java.lang.String getName() throws StandardException
Description copied from interface:Optimizable
Get the (exposed) name of this Optimizable- Specified by:
getName
in interfaceOptimizable
- Returns:
- The name of this Optimizable.
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.getName()
-
getBaseTableName
public java.lang.String getBaseTableName()
Description copied from interface:Optimizable
Get the table name of this Optimizable. Only base tables have table names (by the time we use this method, all views will have been resolved).- Specified by:
getBaseTableName
in interfaceOptimizable
- See Also:
Optimizable.getBaseTableName()
-
convertAbsoluteToRelativeColumnPosition
public int convertAbsoluteToRelativeColumnPosition(int absolutePosition)
Description copied from interface:Optimizable
Convert an absolute to a relative 0-based column position. This is useful when generating qualifiers for partial rows from the store.- Specified by:
convertAbsoluteToRelativeColumnPosition
in interfaceOptimizable
- Parameters:
absolutePosition
- The absolute 0-based column position for the column.- Returns:
- The relative 0-based column position for the column.
- See Also:
Optimizable.convertAbsoluteToRelativeColumnPosition(int)
-
updateBestPlanMap
public void updateBestPlanMap(short action, java.lang.Object planKey) throws StandardException
Description copied from interface:Optimizable
When remembering "truly the best" access path for an Optimizable, we have to keep track of which OptimizerImpl the "truly the best" access is for. In most queries there will only be one OptimizerImpl in question, but in cases where there are nested subqueries, there will be one OptimizerImpl for every level of nesting, and each OptimizerImpl might have its own idea of what this Optimizable's "truly the best path" access path really is. In addition, there could be Optimizables above this Optimizable that might need to override the best path chosen during optimization. So whenever we save a "truly the best" path, we take note of which Optimizer/Optimizable told us to do so. Then as each level of subquery finishes optimization, the corresponding OptimizerImpl/Optimizable can load its preferred access path into this Optimizable's trulyTheBestAccessPath field and pass it up the tree, until eventually the outer-most OptimizerImpl can choose to either use the best path that it received from below (by calling "rememberAsBest()") or else use the path that it found to be "best" for itself. This method is what allows us to keep track of which OptimizerImpl or Optimizable saved which "best plan", and allows us to load the appropriate plans after each round of optimization.- Specified by:
updateBestPlanMap
in interfaceOptimizable
- Parameters:
action
- Indicates whether we're adding, loading, or removing a best plan for the OptimizerImpl/Optimizable.planKey
- Object to use as the map key when adding/looking up a plan. If it is an instance of OptimizerImpl then it corresponds to an outer query; otherwise it's some Optimizable above this Optimizable that could potentially reject plans chosen by the OptimizerImpl to which this Optimizable belongs.- Throws:
StandardException
- See Also:
Optimizable.updateBestPlanMap(short, java.lang.Object)
-
rememberAsBest
public void rememberAsBest(int planType, Optimizer optimizer) throws StandardException
Description copied from interface:Optimizable
Remember the current access path as the best one (so far).- Specified by:
rememberAsBest
in interfaceOptimizable
- Parameters:
planType
- The type of plan (one of Optimizer.NORMAL_PLAN or Optimizer.SORT_AVOIDANCE_PLAN)optimizer
- The OptimizerImpl that is telling this Optimizable to remember its current path as "truly the best".- Throws:
StandardException
- thrown on error.- See Also:
Optimizable.rememberAsBest(int, org.apache.derby.iapi.sql.compile.Optimizer)
-
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 interfaceOptimizable
- See Also:
Optimizable.startOptimizing(org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.RowOrdering)
-
resetJoinStrategies
protected void resetJoinStrategies(Optimizer optimizer)
This method is called when this table is placed in a potential join order, or when a new conglomerate is being considered. Set this join strategy number to 0 to indicate that no join strategy has been considered for this table yet.
-
estimateCost
public CostEstimate estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering) throws StandardException
Description copied from interface:Optimizable
Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate. It is assumed that the predicate list has already been classified. This cost estimate is just for one scan, not for the life of the query.- Specified by:
estimateCost
in interfaceOptimizable
- Parameters:
predList
- The predicate list to optimize againstcd
- The conglomerate descriptor to get the cost ofouterCost
- The estimated cost of the part of the plan outer to this optimizable.optimizer
- The optimizer to use to help estimate the costrowOrdering
- The row ordering for all the tables in the join order, including this one.- Returns:
- The estimated cost of doing the scan
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.estimateCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor, org.apache.derby.iapi.sql.compile.CostEstimate, org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.RowOrdering)
-
getFinalCostEstimate
CostEstimate getFinalCostEstimate() throws StandardException
Get the final CostEstimate for this FromTable.- Overrides:
getFinalCostEstimate
in classResultSetNode
- Returns:
- The final CostEstimate for this FromTable, which is the costEstimate of trulyTheBestAccessPath if there is one. If there's no trulyTheBestAccessPath for this node, then we just return the value stored in costEstimate as a default.
- Throws:
StandardException
-
isBaseTable
public boolean isBaseTable()
Description copied from interface:Optimizable
Tell whether this Optimizable represents a base table- Specified by:
isBaseTable
in interfaceOptimizable
- See Also:
Optimizable.isBaseTable()
-
hasLargeObjectColumns
public boolean hasLargeObjectColumns()
Check if any columns containing large objects (BLOBs or CLOBs) are referenced in this table.- Specified by:
hasLargeObjectColumns
in interfaceOptimizable
- Returns:
true
if at least one large object column is referenced,false
otherwise
-
isMaterializable
public boolean isMaterializable() throws StandardException
Description copied from interface:Optimizable
Tell whether this Optimizable is materializable- Specified by:
isMaterializable
in interfaceOptimizable
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.isMaterializable()
-
supportsMultipleInstantiations
public boolean supportsMultipleInstantiations()
Description copied from interface:Optimizable
Tell whether this Optimizable can be instantiated multiple times- Specified by:
supportsMultipleInstantiations
in interfaceOptimizable
- See Also:
Optimizable.supportsMultipleInstantiations()
-
getTableNumber
public int getTableNumber()
Description copied from interface:Optimizable
Get this Optimizable's table number- Specified by:
getTableNumber
in interfaceOptimizable
- See Also:
Optimizable.getTableNumber()
-
hasTableNumber
public boolean hasTableNumber()
Description copied from interface:Optimizable
Return true if this Optimizable has a table number- Specified by:
hasTableNumber
in interfaceOptimizable
- See Also:
Optimizable.hasTableNumber()
-
forUpdate
public boolean forUpdate()
Description copied from interface:Optimizable
Return true if this is the target table of an update- Specified by:
forUpdate
in interfaceOptimizable
- See Also:
Optimizable.forUpdate()
-
initialCapacity
public int initialCapacity()
Description copied from interface:Optimizable
Return the initial capacity of the hash table, for hash join strategy- Specified by:
initialCapacity
in interfaceOptimizable
- See Also:
Optimizable.initialCapacity()
-
loadFactor
public float loadFactor()
Description copied from interface:Optimizable
Return the load factor of the hash table, for hash join strategy- Specified by:
loadFactor
in interfaceOptimizable
- See Also:
Optimizable.loadFactor()
-
maxCapacity
public int maxCapacity(JoinStrategy joinStrategy, int maxMemoryPerTable) throws StandardException
Description copied from interface:Optimizable
Return the maximum capacity of the hash table, for hash join strategy- Specified by:
maxCapacity
in interfaceOptimizable
maxMemoryPerTable
- The maximum number of bytes to be used. Ignored if the user has set a maximum number of rows for the Optimizable.- Throws:
StandardException
- Standard error policy- See Also:
Optimizable.maxCapacity(org.apache.derby.iapi.sql.compile.JoinStrategy, int)
-
getPerRowUsage
private double getPerRowUsage() throws StandardException
- Throws:
StandardException
-
hashKeyColumns
public int[] hashKeyColumns()
Description copied from interface:Optimizable
Return the hash key column numbers, for hash join strategy- Specified by:
hashKeyColumns
in interfaceOptimizable
- See Also:
Optimizable.hashKeyColumns()
-
setHashKeyColumns
public void setHashKeyColumns(int[] columnNumbers)
Description copied from interface:Optimizable
Set the hash key column numbers, for hash join strategy- Specified by:
setHashKeyColumns
in interfaceOptimizable
- See Also:
Optimizable.setHashKeyColumns(int[])
-
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 interfaceOptimizable
- Parameters:
predList
- The predicate list that has been pushed down to this optimizableoptimizer
- The optimizer to use.- Returns:
- true means feasible
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.feasibleJoinStrategy(org.apache.derby.iapi.sql.compile.OptimizablePredicateList, org.apache.derby.iapi.sql.compile.Optimizer)
-
memoryUsageOK
public boolean memoryUsageOK(double rowCount, int maxMemoryPerTable) throws StandardException
- Specified by:
memoryUsageOK
in interfaceOptimizable
- Returns:
- true if the memory usage of the proposed access path is OK, false if not.
- Throws:
StandardException
- standard error policy- See Also:
Optimizable.memoryUsageOK(double, int)
-
isJoinColumnForRightOuterJoin
void isJoinColumnForRightOuterJoin(ResultColumn rc)
No-op in FromTable.
-
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 interfaceOptimizable
- Parameters:
assignedTableMap
- The tables that have been placed so far in the join order.- Returns:
- Where or not this Optimizable can appear at the current location in the join order.
- See Also:
Optimizable.legalJoinOrder(org.apache.derby.iapi.util.JBitSet)
-
getNumColumnsReturned
public int getNumColumnsReturned()
Description copied from interface:Optimizable
Get the number of the number of columns returned by this Optimizable.- Specified by:
getNumColumnsReturned
in interfaceOptimizable
- Returns:
- The number of the number of columns returned by this Optimizable.
- See Also:
Optimizable.getNumColumnsReturned()
-
isTargetTable
public boolean isTargetTable()
Description copied from interface:Optimizable
Is the optimizable the target table of an update or delete?- Specified by:
isTargetTable
in interfaceOptimizable
- Returns:
- Whether or not the optimizable the target table of an update or delete.
- See Also:
Optimizable.isTargetTable()
-
isOneRowScan
public boolean isOneRowScan() throws StandardException
Description copied from interface:Optimizable
Will the optimizable return at most 1 row per scan?- Specified by:
isOneRowScan
in interfaceOptimizable
- Returns:
- Whether or not the optimizable will return at most 1 row per scan?
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.isOneRowScan()
-
initAccessPaths
public void initAccessPaths(Optimizer optimizer)
Description copied from interface:Optimizable
Init the access paths for this optimizable.- Specified by:
initAccessPaths
in interfaceOptimizable
- Parameters:
optimizer
- The optimizer being used.- See Also:
Optimizable.initAccessPaths(org.apache.derby.iapi.sql.compile.Optimizer)
-
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 interfaceOptimizable
- Parameters:
predList
- The predicate list to check- Returns:
- <= 0 means there is no uniqueness condition > 0 means there is a uniqueness condition, and the return value is the number of rows per scan.
- Throws:
StandardException
- Thrown on error- See Also:
Optimizable.uniqueJoin(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)
-
getUserSpecifiedJoinStrategy
java.lang.String getUserSpecifiedJoinStrategy()
Return the user specified join strategy, if any for this table.- Returns:
- The user specified join strategy, if any for this table.
-
cursorTargetTable
protected boolean cursorTargetTable()
Is this a table that has a FOR UPDATE clause. Overridden by FromBaseTable.- Returns:
- true/false
-
getCostEstimate
protected CostEstimate getCostEstimate(Optimizer optimizer)
-
getScratchCostEstimate
protected CostEstimate getScratchCostEstimate(Optimizer optimizer)
-
setCostEstimateCost
protected void setCostEstimateCost(CostEstimate newCostEstimate)
Set the cost estimate in this node to the given cost estimate.
-
assignCostEstimate
protected void assignCostEstimate(CostEstimate newCostEstimate)
Assign the cost estimate in this node to the given cost estimate.
-
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 classResultSetNode
- Returns:
- This object as a String
-
getResultColumnsForList
ResultColumnList getResultColumnsForList(TableName allTableName, ResultColumnList inputRcl, TableName tableName) throws StandardException
Return a ResultColumnList with all of the columns in this table. (Used in expanding '*'s.) NOTE: Since this method is for expanding a "*" in the SELECT list, ResultColumn.expression will be a ColumnReference.- Parameters:
allTableName
- The qualifier on the "*"- Returns:
- ResultColumnList List of result columns from this table.
- Throws:
StandardException
- Thrown on error
-
pushExpressions
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.- Parameters:
predicateList
- The PredicateList.- Throws:
StandardException
- Thrown on error
-
getExposedName
java.lang.String getExposedName() throws StandardException
Get the exposed name for this table, which is the name that can be used to refer to it in the rest of the query.- Returns:
- The exposed name of this table.
- Throws:
StandardException
- Thrown on error
-
setTableNumber
void setTableNumber(int tableNumber)
Set the table # for this table.- Parameters:
tableNumber
- The table # for this table.
-
getTableName
TableName getTableName() throws StandardException
Return a TableName node representing this FromTable. Expect this to be overridden (and used) by subclasses that may set correlationName to null.- Returns:
- a TableName node representing this FromTable.
- Throws:
StandardException
- Thrown on error
-
setLevel
void setLevel(int level)
Set the (query block) level (0-based) for this FromTable.- Parameters:
level
- The query block level for this FromTable.
-
getLevel
int getLevel()
Get the (query block) level (0-based) for this FromTable.- Returns:
- int The query block level for this FromTable.
-
decrementLevel
void decrementLevel(int decrement)
Decrement (query block) level (0-based) for this FromTable. This is useful when flattening a subquery.- Specified by:
decrementLevel
in classResultSetNode
- Parameters:
decrement
- The amount to decrement by.
-
getSchemaDescriptor
SchemaDescriptor getSchemaDescriptor() throws StandardException
Get a schema descriptor for the given table. Uses this.corrTableName.- Returns:
- Schema Descriptor
- Throws:
StandardException
- throws on schema name that doesn't exist
-
getSchemaDescriptor
SchemaDescriptor getSchemaDescriptor(TableName tableName) throws StandardException
Get a schema descriptor for the given table.- Parameters:
tableName
- the table name- Returns:
- Schema Descriptor
- Throws:
StandardException
- throws on schema name that doesn't exist
-
getFromTableByName
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 classResultSetNode
- 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
-
isFlattenableJoinNode
boolean isFlattenableJoinNode()
Is this FromTable a JoinNode which can be flattened into the parents FromList.- Returns:
- boolean Whether or not this FromTable can be flattened.
-
LOJ_reorderable
boolean LOJ_reorderable(int numTables) throws StandardException
no LOJ reordering for this FromTable.- Throws:
StandardException
-
transformOuterJoins
FromTable transformOuterJoins(ValueNode predicateTree, int numTables) throws StandardException
Transform any Outer Join into an Inner Join where applicable. (Based on the existence of a null intolerant predicate on the inner table.)- Parameters:
predicateTree
- The predicate tree for the query block- Returns:
- The new tree top (OuterJoin or InnerJoin).
- Throws:
StandardException
- Thrown on error
-
fillInReferencedTableMap
void fillInReferencedTableMap(JBitSet passedMap)
Fill the referencedTableMap with this ResultSetNode.- Overrides:
fillInReferencedTableMap
in classResultSetNode
- Parameters:
passedMap
- The table map to fill in.
-
markUpdatableByCursor
protected void markUpdatableByCursor(java.util.List<java.lang.String> updateColumns)
Mark as updatable all the columns in the result column list of this FromBaseTable that match the columns in the given update column list. If the list is null, it means all the columns are updatable.- Parameters:
updateColumns
- A list representing the columns that can be updated.
-
columnsAreUpdatable
boolean columnsAreUpdatable()
Return true if some columns in this table are updatable. This method is used in deciding whether updateRow() or insertRow() are allowable.- Returns:
- true if some columns in this table are updatable.
-
flatten
FromList flatten(ResultColumnList rcl, PredicateList outerPList, SubqueryList sql, GroupByList gbl, ValueNode havingClause) throws StandardException
Flatten this FromTable into the outer query block. The steps in flattening are: o Mark all ResultColumns as redundant, so that they are "skipped over" at generate(). o Append the wherePredicates to the outer list. o Return the fromList so that the caller will merge the 2 lists- Parameters:
rcl
- The RCL from the outer queryouterPList
- PredicateList to append wherePredicates to.sql
- The SubqueryList from the outer querygbl
- The group by list, if anyhavingClause
- The HAVING clause, if any- Returns:
- FromList The fromList from the underlying SelectNode.
- Throws:
StandardException
- Thrown on error
-
optimizeSubqueries
void optimizeSubqueries(DataDictionary dd, double rowCount) throws StandardException
Optimize any subqueries that haven't been optimized any where else. This is useful for a RowResultSetNode as a derived table because it doesn't get optimized otherwise.- Throws:
StandardException
- Thrown on error
-
tellRowOrderingAboutConstantColumns
protected void tellRowOrderingAboutConstantColumns(RowOrdering rowOrdering, OptimizablePredicateList predList)
Tell the given RowOrdering about any columns that are constant due to their being equality comparisons with constant expressions.
-
needsSpecialRCLBinding
boolean needsSpecialRCLBinding()
-
setOrigTableName
void setOrigTableName(TableName tableName)
Sets the original or unbound table name for this FromTable.- Parameters:
tableName
- the unbound table name
-
getOrigTableName
TableName getOrigTableName()
Gets the original or unbound table name for this FromTable. The tableName field can be changed due to synonym resolution. Use this method to retrieve the actual unbound tablename.- Returns:
- TableName the original or unbound tablename
-
setMergeTableID
void setMergeTableID(int mergeTableID)
set the merge table id
-
getMergeTableID
int getMergeTableID()
get the merge table id
-
acceptChildren
void acceptChildren(Visitor v) throws StandardException
Description copied from class:ResultSetNode
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildren
in classResultSetNode
- Parameters:
v
- the visitor- Throws:
StandardException
- on error
-
-