Class FromBaseTable
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.ResultSetNode
-
- org.apache.derby.impl.sql.compile.FromTable
-
- org.apache.derby.impl.sql.compile.FromBaseTable
-
- All Implemented Interfaces:
Optimizable,Visitable
class FromBaseTable extends FromTable
A FromBaseTable represents a table in the FROM list of a DML statement, as distinguished from a FromSubquery, which represents a subquery in the FROM list. A FromBaseTable may actually represent a view. During parsing, we can't distinguish views from base tables. During binding, when we find FromBaseTables that represent views, we replace them with FromSubqueries. By the time we get to code generation, all FromSubqueries have been eliminated, and all FromBaseTables will represent only true base tables.Positioned Update: Currently, all columns of an updatable cursor are selected to deal with a positioned update. This is because we don't know what columns will ultimately be needed from the UpdateNode above us. For example, consider:
get c as 'select cint from t for update of ctinyint' update t set ctinyint = csmallintIdeally, the cursor only selects cint. Then, something akin to an IndexRowToBaseRow is generated to take the CursorResultSet and get the appropriate columns out of the base table from the RowLocation returned by the cursor. Then the update node can generate the appropriate NormalizeResultSet (or whatever else it might need) to get things into the correct format for the UpdateResultSet. See CurrentOfNode for more information.
-
-
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 booleanauthorizeSYSUSERS(package private) ConglomerateDescriptorbaseConglomerateDescriptor(package private) PredicateListbaseTableRestrictionListRestriction as a PredicateList(package private) intbulkFetch(package private) booleanbulkFetchTurnedOffprivate java.lang.String[]columnNames(package private) ConglomerateDescriptor[]conglomDescs(package private) static intDELETEprivate JBitSetdependencyMapprivate booleandistinctScanprivate booleanexistsBaseTableprivate int[]fkColArrayprivate longfkIndexConglomIdprivate booleangetUpdateLocksprivate booleangotRowCountprivate booleanhasCheckedIndexStatsWhether or not we have checked the index statistics for staleness.private booleanisNotExists(package private) booleanmultiProbing(package private) PredicateListnonBaseTableRestrictionList(package private) PredicateListnonStoreRestrictionListprivate booleanraDependentScanInformation for dependent table scan for Referential Actionsprivate java.lang.StringraParentResultSetIdprivate FormatableBitSetreferencedCols(package private) PredicateListrequalificationRestrictionList(package private) PredicateListrestrictionListprivate longrowCountprivate java.lang.StringrowLocationColumnNameprivate doublesingleScanRowCountprivate booleanspecialMaxScan(package private) PredicateListstoreRestrictionList(package private) TableDescriptortableDescriptor(package private) TableNametableNameprivate java.lang.StringtargetTableUUIDStringprivate ResultColumnListtemplateColumns(package private) static intUNSET(package private) static intUPDATE(package private) intupdateOrDeleteprivate booleanvalidatingCheckConstraint-
Fields inherited from class org.apache.derby.impl.sql.compile.FromTable
ADD_PLAN, bestAccessPath, bestCostEstimate, bestSortAvoidancePath, correlationName, corrTableName, currentAccessPath, hashKeyColumns, initialCapacity, level, LOAD_PLAN, loadFactor, maxCapacity, origTableName, REMOVE_PLAN, tableNumber, tableProperties, trulyTheBestAccessPath, 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 FromBaseTable(TableName tableName, java.lang.String correlationName, int updateOrDelete, ResultColumnList derivedRCL, ContextManager cm)Initializer for a table in a FROM list.FromBaseTable(TableName tableName, java.lang.String correlationName, ResultColumnList derivedRCL, 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) voidacceptChildren(Visitor v)Accept the visitor for all visitable children of this node.(package private) ResultColumnListaddColsToList(ResultColumnList inputRcl, FormatableBitSet colsWeWant)Augment the RCL to include the columns in the FormatableBitSet.(package private) voidadjustForSortElimination()Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort.(package private) voidadjustForSortElimination(RequiredRowOrdering rowOrdering)Same goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed.private longbaseRowCount()(package private) voidbindExpressions(FromList fromListParam)Bind the expressions in this FromBaseTable.(package private) ResultSetNodebindNonVTITables(DataDictionary dataDictionary, FromList fromListParam)Bind the table in this FromBaseTable.(package private) voidbindResultColumns(FromList fromListParam)Bind the result columns of this ResultSetNode when there is no base table to bind them to.private TableDescriptorbindTableDescriptor()Bind the table descriptor for this table.protected booleancanBeOrdered()Tell super-class that this Optimizable can be ordered(package private) ResultSetNodechangeAccessPath()The optimizer's decision on the access path for a result set may require the generation of extra result sets.(package private) voidclearDependency(java.util.List<java.lang.Integer> locations)Clear the bits from the dependency map when join nodes are flattenedintconvertAbsoluteToRelativeColumnPosition(int absolutePosition)Convert an absolute to a relative 0-based column position.protected booleancursorTargetTable()Is this a table that has a FOR UPDATE clause?(package private) voiddisableBulkFetch()Turn off bulk fetch(package private) voiddoSpecialMaxScan()Do a special scan for max.CostEstimateestimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering)Estimate the cost of scanning thisFromBaseTableusing the given predicate list with the given conglomerate.booleanforUpdate()Return true if this is the target table of an update(package private) voidgenerate(ActivationClassBuilder acb, MethodBuilder mb)Generation on a FromBaseTable creates a scan on the optimizer-selected conglomerate.private voidgenerateDistinctScan(ExpressionClassBuilder acb, MethodBuilder mb)private voidgenerateMaxSpecialResultSet(ExpressionClassBuilder acb, MethodBuilder mb)private voidgenerateRefActionDependentTableScan(ExpressionClassBuilder acb, MethodBuilder mb)Generation on a FromBaseTable for a referential action dependent table.(package private) voidgenerateResultSet(ExpressionClassBuilder acb, MethodBuilder mb)Generation on a FromBaseTable for a SELECT.protected ResultSetNodegenProjectRestrict(int numTables)Put a ProjectRestrictNode on top of each FromTable in the FromList.(package private) ResultColumnListgenResultColList()Build a ResultColumnList based on all of the columns in this FromBaseTable.(package private) ResultColumnListgetAllResultColumns(TableName allTableName)Return a ResultColumnList with all of the columns in this table.private StoreCostControllergetBaseCostController()java.lang.StringgetBaseTableName()Get the table name of this Optimizable.private voidgetConglomDescs()private intgetDefaultBulkFetch()(package private) booleangetExistsBaseTable()Does this FBT represent an EXISTS FBT.(package private) java.lang.StringgetExposedName()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) TableNamegetExposedTableName()Get the exposed table name for this table, which is the name that can be used to refer to it in the rest of the query.(package private) CostEstimategetFinalCostEstimate()Get the final CostEstimate for this ResultSetNode.private ConglomerateDescriptorgetFirstConglom()(package private) FromTablegetFromTableByName(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) ResultColumngetMatchingColumn(ColumnReference columnReference)Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.private ConglomerateDescriptorgetNextConglom(ConglomerateDescriptor currCD)private DataValueDescriptor[]getRowTemplate(ConglomerateDescriptor cd, StoreCostController scc)private intgetScanArguments(ExpressionClassBuilder acb, MethodBuilder mb)private StoreCostControllergetStoreCostController(ConglomerateDescriptor cd)TableDescriptorgetTableDescriptor()Get the table descriptor for this table (if any).(package private) TableNamegetTableName()Return a TableName node representing this FromTable.(package private) TableNamegetTableNameField()Return the table name for this table.private java.lang.StringgetUserSpecifiedIndexName()intinitialCapacity()Return the initial capacity of the hash table, for hash join strategybooleanisBaseTable()Tell whether this Optimizable represents a base tablebooleanisCoveringIndex(ConglomerateDescriptor cd)Return whether or not this is a covering index.booleanisMaterializable()Tell whether this Optimizable is materializable(package private) booleanisNotExists()Return whether or not this is actually a EBT for NOT EXISTS.(package private) booleanisOneRowResultSet()Return whether or not the underlying ResultSet tree will return a single row, at most.(package private) booleanisOneRowResultSet(OptimizablePredicateList predList)private booleanisOneRowResultSet(ConglomerateDescriptor cd, OptimizablePredicateList predList)Is this a one-row result set with the given conglomerate descriptor?booleanisOneRowScan()Will the optimizable return at most 1 row per scan?private booleanisOrdered(ColumnReference[] crs, ConglomerateDescriptor cd)Return whether or not this index is ordered on a permutation of the specified columns.(package private) booleanisOrderedOn(ColumnReference[] crs, boolean permuteOrdering, java.util.List<FromBaseTable> fbtHolder)Return whether or not the underlying ResultSet tree is ordered on the specified columns.(package private) booleanisPossibleDistinctScan(java.util.Set<BaseColumnNode> distinctColumns)Is it possible to do a distinct scan on this ResultSet tree.private booleanisStrictlyOrdered(ColumnReference[] crs, ConglomerateDescriptor cd)Return whether or not this index is ordered on a permutation of the specified columns.booleanisTargetTable()Is the optimizable the target table of an update or delete?private booleanisValidatingCheckConstraint()booleanlegalJoinOrder(JBitSet assignedTableMap)Can this Optimizable appear at the current location in the join order.floatloadFactor()Return the load factor of the hash table, for hash join strategy(package private) booleanLOJ_reorderable(int numTables)no LOJ reordering for base table.(package private) JBitSetLOJgetReferencedTables(int numTables)private intmapAbsoluteToRelativeColumnPosition(int absolutePosition)Convert an absolute to a relative 0-based column position.private ResultSetNodemapTableAsVTI(TableDescriptor td, java.lang.String correlationName, ResultColumnList resultColumns, java.util.Properties tableProperties, ContextManager cm)Return a node that represents invocation of the virtual table for the given table descriptor.(package private) booleanmarkAsCursorTargetTable()Mark this ResultSetNode as the target table of an updatable cursor.(package private) voidmarkForDistinctScan()Mark the underlying scan as a distinct scan.(package private) voidmarkUpdated(ResultColumnList 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.booleanmemoryUsageOK(double rowCount, int maxMemoryPerTable)private ResultColumnListnewResultColumns(ResultColumnList oldColumns, ConglomerateDescriptor idxCD, ConglomerateDescriptor heapCD, boolean cloneRCs)Create a new ResultColumnList to reflect the columns in the index described by the given ConglomerateDescriptor.booleannextAccessPath(Optimizer optimizer, OptimizablePredicateList predList, RowOrdering rowOrdering)Choose the next access path to evaluate for this Optimizable.CostEstimateoptimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering)Choose the best access path for this Optimizable.(package private) ResultSetNodepreprocess(int numTables, GroupByList gbl, FromList fromList)Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode.voidpullOptPredicates(OptimizablePredicateList optimizablePredicates)Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.private voidpushIndexName(ConglomerateDescriptor cd, MethodBuilder mb)booleanpushOptPredicate(OptimizablePredicate optimizablePredicate)Push an OptimizablePredicate down, if this node accepts it.private booleanqualifiesForStatisticsUpdateCheck(TableDescriptor td)Tells if the given table qualifies for a statistics update check in the current configuration.booleanreferencesSessionSchema()Return true if the node references SESSION schema tables (temporary or permanent)(package private) booleanreferencesTarget(java.lang.String name, boolean baseTable)Search to see if a query references the specifed table name.private doublescanCostAfterSelectivity(double originalScanCost, double initialPositionCost, double selectivity, boolean anotherIndexUnique)(package private) voidsetExistsBaseTable(boolean existsBaseTable, JBitSet dependencyMap, boolean isNotExists)Set whether or not this FBT represents an EXISTS FBT.private voidsetLockingBasedOnThreshold(Optimizer optimizer, double rowsTouched)(package private) voidsetRefActionInfo(long fkIndexConglomId, int[] fkColArray, java.lang.String parentResultSetId, boolean dependentScan)set the Information gathered from the parent table that is required to perform a referential action on dependent table.(package private) voidsetRowLocationColumnName(java.lang.String rowLocationColumnName)Set the name of the row location column(package private) voidsetTableProperties(java.util.Properties tableProperties)Set the table properties for this table.voidstartOptimizing(Optimizer optimizer, RowOrdering rowOrdering)Begin the optimization process for this Optimizable.protected booleansupersetOfUniqueIndex(boolean[] eqCols)Determine whether or not the columns marked as true in the passed in array are a superset of any unique index on this table.protected booleansupersetOfUniqueIndex(JBitSet[] tableColMap)Determine whether or not the columns marked as true in the passed in join table matrix are a superset of any single column unique index on this table.java.lang.StringtoString()Convert this object to a String.doubleuniqueJoin(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.(package private) intupdateTargetLockMode()Get the lock mode for the target table heap of an update or delete statement.voidverifyProperties(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
assignCostEstimate, columnsAreUpdatable, considerSortAvoidancePath, decrementLevel, feasibleJoinStrategy, fillInReferencedTableMap, flatten, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getLevel, getMergeTableID, getName, getNumColumnsReturned, getOrigTableName, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableNumber, getTrulyTheBestAccessPath, getUserSpecifiedJoinStrategy, hashKeyColumns, hasLargeObjectColumns, hasTableNumber, initAccessPaths, isFlattenableJoinNode, isJoinColumnForRightOuterJoin, markUpdatableByCursor, maxCapacity, modifyAccessPath, needsSpecialRCLBinding, optimizeSubqueries, pushExpressions, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimateCost, setHashKeyColumns, setLevel, setMergeTableID, setOrigTableName, setProperties, setTableNumber, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, transformOuterJoins, updateBestPlanMap
-
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, assignResultSetNumber, bindExpressionsWithTables, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, bindVTITables, columnTypesAndLengthsMatch, considerMaterialization, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, generateNormalizationResultSet, genProjectRestrict, genProjectRestrictForReordering, getCandidateFinalCostEstimate, getCostEstimate, getCursorTargetTable, getFromList, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, getScratchCostEstimate, isCursorTargetTable, isInsertSource, isStatementResultSet, isUpdatableCursor, makeResultDescription, makeResultDescriptors, markStatementResultSet, modifyAccessPaths, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, optimize, parseDefault, performMaterialization, printQueryExpressionSuffixClauses, printSubNodes, projectResultColumns, pushOffsetFetchFirst, pushOrderByList, pushQueryExpressionSuffix, rejectParameters, rejectXMLValues, renameGeneratedResultNames, replaceOrForbidDefaults, returnsAtMostOneRow, setCandidateFinalCostEstimate, setCostEstimate, setCursorTargetTable, setInsertSource, setOptimizer, setReferencedTableMap, setResultColumns, setResultSetNumber, setResultToBooleanTrueNode, setScratchCostEstimate, setTableConstructorTypes, subqueryReferencesTarget, 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, 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, resolveTableToSynonym, setBeginOffset, setEndOffset, 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
-
UNSET
static final int UNSET
- See Also:
- Constant Field Values
-
hasCheckedIndexStats
private boolean hasCheckedIndexStats
Whether or not we have checked the index statistics for staleness. Used to avoid performing the check multiple times per compilation.
-
tableName
TableName tableName
-
tableDescriptor
TableDescriptor tableDescriptor
-
baseConglomerateDescriptor
ConglomerateDescriptor baseConglomerateDescriptor
-
conglomDescs
ConglomerateDescriptor[] conglomDescs
-
updateOrDelete
int updateOrDelete
-
bulkFetch
int bulkFetch
-
targetTableUUIDString
private java.lang.String targetTableUUIDString
-
validatingCheckConstraint
private boolean validatingCheckConstraint
-
bulkFetchTurnedOff
boolean bulkFetchTurnedOff
-
multiProbing
boolean multiProbing
-
singleScanRowCount
private double singleScanRowCount
-
referencedCols
private FormatableBitSet referencedCols
-
templateColumns
private ResultColumnList templateColumns
-
columnNames
private java.lang.String[] columnNames
-
specialMaxScan
private boolean specialMaxScan
-
distinctScan
private boolean distinctScan
-
raDependentScan
private boolean raDependentScan
Information for dependent table scan for Referential Actions
-
raParentResultSetId
private java.lang.String raParentResultSetId
-
fkIndexConglomId
private long fkIndexConglomId
-
fkColArray
private int[] fkColArray
-
baseTableRestrictionList
PredicateList baseTableRestrictionList
Restriction as a PredicateList
-
nonBaseTableRestrictionList
PredicateList nonBaseTableRestrictionList
-
restrictionList
PredicateList restrictionList
-
storeRestrictionList
PredicateList storeRestrictionList
-
nonStoreRestrictionList
PredicateList nonStoreRestrictionList
-
requalificationRestrictionList
PredicateList requalificationRestrictionList
-
UPDATE
static final int UPDATE
- See Also:
- Constant Field Values
-
DELETE
static final int DELETE
- See Also:
- Constant Field Values
-
existsBaseTable
private boolean existsBaseTable
-
isNotExists
private boolean isNotExists
-
dependencyMap
private JBitSet dependencyMap
-
getUpdateLocks
private boolean getUpdateLocks
-
authorizeSYSUSERS
private boolean authorizeSYSUSERS
-
rowLocationColumnName
private java.lang.String rowLocationColumnName
-
gotRowCount
private boolean gotRowCount
-
rowCount
private long rowCount
-
-
Constructor Detail
-
FromBaseTable
FromBaseTable(TableName tableName, java.lang.String correlationName, ResultColumnList derivedRCL, java.util.Properties tableProperties, ContextManager cm)
Constructor for a table in a FROM list. Parameters are as follows:- Parameters:
tableName- The name of the tablecorrelationName- The correlation namederivedRCL- The derived column listtableProperties- The Properties list associated with the table.cm- The context manager
-
FromBaseTable
FromBaseTable(TableName tableName, java.lang.String correlationName, int updateOrDelete, ResultColumnList derivedRCL, ContextManager cm)
Initializer for a table in a FROM list. Parameters are as follows:- Parameters:
tableName- The name of the tablecorrelationName- The correlation nameupdateOrDelete- Table is being updated/deleted from.derivedRCL- The derived column listcm- The context manager
-
-
Method Detail
-
setRowLocationColumnName
void setRowLocationColumnName(java.lang.String rowLocationColumnName)
Set the name of the row location column
-
LOJ_reorderable
boolean LOJ_reorderable(int numTables) throws StandardExceptionno LOJ reordering for base table.- Overrides:
LOJ_reorderablein classFromTable- Throws:
StandardException
-
LOJgetReferencedTables
JBitSet LOJgetReferencedTables(int numTables) throws StandardException
- Overrides:
LOJgetReferencedTablesin classResultSetNode- Throws:
StandardException
-
nextAccessPath
public boolean nextAccessPath(Optimizer optimizer, OptimizablePredicateList predList, RowOrdering rowOrdering) throws StandardException
Description copied from interface:OptimizableChoose the next access path to evaluate for this Optimizable.- Specified by:
nextAccessPathin interfaceOptimizable- Overrides:
nextAccessPathin classFromTable- 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()
Tell super-class that this Optimizable can be ordered- Overrides:
canBeOrderedin classFromTable
-
optimizeIt
public CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering) throws StandardException
Description copied from interface:OptimizableChoose the best access path for this Optimizable.- Specified by:
optimizeItin interfaceOptimizable- Overrides:
optimizeItin classFromTable- 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)
-
getTableDescriptor
public TableDescriptor getTableDescriptor()
Description copied from interface:OptimizableGet 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:
getTableDescriptorin interfaceOptimizable- Overrides:
getTableDescriptorin classFromTable- See Also:
Optimizable.getTableDescriptor()
-
isMaterializable
public boolean isMaterializable() throws StandardExceptionDescription copied from interface:OptimizableTell whether this Optimizable is materializable- Specified by:
isMaterializablein interfaceOptimizable- Overrides:
isMaterializablein classFromTable- Throws:
StandardException- Thrown on error- See Also:
Optimizable.isMaterializable()
-
pushOptPredicate
public boolean pushOptPredicate(OptimizablePredicate optimizablePredicate) throws StandardException
Description copied from interface:OptimizablePush an OptimizablePredicate down, if this node accepts it.- Specified by:
pushOptPredicatein interfaceOptimizable- Overrides:
pushOptPredicatein classFromTable- 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:OptimizablePull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.- Specified by:
pullOptPredicatesin interfaceOptimizable- Overrides:
pullOptPredicatesin classFromTable- 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)
-
isCoveringIndex
public boolean isCoveringIndex(ConglomerateDescriptor cd) throws StandardException
Description copied from interface:OptimizableReturn whether or not this is a covering index. We expect to call this during generation, after access path selection is complete.- Specified by:
isCoveringIndexin interfaceOptimizable- Overrides:
isCoveringIndexin classFromTable- 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)
-
verifyProperties
public void verifyProperties(DataDictionary dDictionary) throws StandardException
Description copied from interface:OptimizableVerify that the Properties list with optimizer overrides, if specified, is valid- Specified by:
verifyPropertiesin interfaceOptimizable- Overrides:
verifyPropertiesin classFromTable- Parameters:
dDictionary- The DataDictionary to use.- Throws:
StandardException- Thrown on error- See Also:
Optimizable.verifyProperties(org.apache.derby.iapi.sql.dictionary.DataDictionary)
-
isValidatingCheckConstraint
private boolean isValidatingCheckConstraint() throws StandardException- Throws:
StandardException
-
getBaseTableName
public java.lang.String getBaseTableName()
Description copied from interface:OptimizableGet 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:
getBaseTableNamein interfaceOptimizable- Overrides:
getBaseTableNamein classFromTable- See Also:
Optimizable.getBaseTableName()
-
startOptimizing
public void startOptimizing(Optimizer optimizer, RowOrdering rowOrdering)
Description copied from interface:OptimizableBegin 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:
startOptimizingin interfaceOptimizable- Overrides:
startOptimizingin classFromTable- See Also:
Optimizable.startOptimizing(org.apache.derby.iapi.sql.compile.Optimizer, org.apache.derby.iapi.sql.compile.RowOrdering)
-
convertAbsoluteToRelativeColumnPosition
public int convertAbsoluteToRelativeColumnPosition(int absolutePosition)
Description copied from interface:OptimizableConvert an absolute to a relative 0-based column position. This is useful when generating qualifiers for partial rows from the store.- Specified by:
convertAbsoluteToRelativeColumnPositionin interfaceOptimizable- Overrides:
convertAbsoluteToRelativeColumnPositionin classFromTable- 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)
-
estimateCost
public CostEstimate estimateCost(OptimizablePredicateList predList, ConglomerateDescriptor cd, CostEstimate outerCost, Optimizer optimizer, RowOrdering rowOrdering) throws StandardException
Estimate the cost of scanning this
FromBaseTableusing the given predicate list with the given conglomerate.If the table contains little data, the cost estimate might be adjusted to make it more likely that an index scan will be preferred to a table scan, and a unique index will be preferred to a non-unique index. Even though such a plan may be slightly suboptimal when seen in isolation, using indexes, unique indexes in particular, needs fewer locks and allows more concurrency.
- Specified by:
estimateCostin interfaceOptimizable- Overrides:
estimateCostin classFromTable- 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)
-
scanCostAfterSelectivity
private double scanCostAfterSelectivity(double originalScanCost, double initialPositionCost, double selectivity, boolean anotherIndexUnique) throws StandardException- Throws:
StandardException
-
setLockingBasedOnThreshold
private void setLockingBasedOnThreshold(Optimizer optimizer, double rowsTouched)
-
isBaseTable
public boolean isBaseTable()
Description copied from interface:OptimizableTell whether this Optimizable represents a base table- Specified by:
isBaseTablein interfaceOptimizable- Overrides:
isBaseTablein classFromTable- See Also:
Optimizable.isBaseTable()
-
forUpdate
public boolean forUpdate()
Description copied from interface:OptimizableReturn true if this is the target table of an update- Specified by:
forUpdatein interfaceOptimizable- Overrides:
forUpdatein classFromTable- See Also:
Optimizable.forUpdate()
-
initialCapacity
public int initialCapacity()
Description copied from interface:OptimizableReturn the initial capacity of the hash table, for hash join strategy- Specified by:
initialCapacityin interfaceOptimizable- Overrides:
initialCapacityin classFromTable- See Also:
Optimizable.initialCapacity()
-
loadFactor
public float loadFactor()
Description copied from interface:OptimizableReturn the load factor of the hash table, for hash join strategy- Specified by:
loadFactorin interfaceOptimizable- Overrides:
loadFactorin classFromTable- See Also:
Optimizable.loadFactor()
-
memoryUsageOK
public boolean memoryUsageOK(double rowCount, int maxMemoryPerTable) throws StandardException- Specified by:
memoryUsageOKin interfaceOptimizable- Overrides:
memoryUsageOKin classFromTable- 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)
-
isTargetTable
public boolean isTargetTable()
Description copied from interface:OptimizableIs the optimizable the target table of an update or delete?- Specified by:
isTargetTablein interfaceOptimizable- Overrides:
isTargetTablein classFromTable- Returns:
- Whether or not the optimizable the target table of an update or delete.
- See Also:
Optimizable.isTargetTable()
-
uniqueJoin
public double uniqueJoin(OptimizablePredicateList predList) throws StandardException
Description copied from interface:OptimizableDoes 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:
uniqueJoinin interfaceOptimizable- Overrides:
uniqueJoinin classFromTable- 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)
-
isOneRowScan
public boolean isOneRowScan() throws StandardExceptionDescription copied from interface:OptimizableWill the optimizable return at most 1 row per scan?- Specified by:
isOneRowScanin interfaceOptimizable- Overrides:
isOneRowScanin classFromTable- Returns:
- Whether or not the optimizable will return at most 1 row per scan?
- Throws:
StandardException- Thrown on error- See Also:
Optimizable.isOneRowScan()
-
legalJoinOrder
public boolean legalJoinOrder(JBitSet assignedTableMap)
Description copied from interface:OptimizableCan this Optimizable appear at the current location in the join order. In other words, have the Optimizable's dependencies been satisfied?- Specified by:
legalJoinOrderin interfaceOptimizable- Overrides:
legalJoinOrderin classFromTable- 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)
-
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.
-
getExistsBaseTable
boolean getExistsBaseTable()
Does this FBT represent an EXISTS FBT.- Returns:
- Whether or not this FBT represents an EXISTS FBT.
-
setExistsBaseTable
void setExistsBaseTable(boolean existsBaseTable, JBitSet dependencyMap, boolean isNotExists)Set whether or not this FBT represents an EXISTS FBT.- Parameters:
existsBaseTable- Whether or not an EXISTS FBT.dependencyMap- The dependency map for the EXISTS FBT.isNotExists- Whether or not for NOT EXISTS, more specifically.
-
clearDependency
void clearDependency(java.util.List<java.lang.Integer> locations)
Clear the bits from the dependency map when join nodes are flattened- Parameters:
locations- list of bit numbers to be cleared
-
setTableProperties
void setTableProperties(java.util.Properties tableProperties)
Set the table properties for this table.- Parameters:
tableProperties- The new table properties.
-
bindNonVTITables
ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) throws StandardException
Bind the table in this FromBaseTable. This is where view resolution occurs- Overrides:
bindNonVTITablesin classResultSetNode- Parameters:
dataDictionary- The DataDictionary to use for bindingfromListParam- FromList to use/append to.- Returns:
- ResultSetNode The FromTable for the table or resolved view.
- Throws:
StandardException- Thrown on error
-
mapTableAsVTI
private ResultSetNode mapTableAsVTI(TableDescriptor td, java.lang.String correlationName, ResultColumnList resultColumns, java.util.Properties tableProperties, ContextManager cm) throws StandardException
Return a node that represents invocation of the virtual table for the given table descriptor. The mapping of the table descriptor to a specific VTI class name will occur as part of the "init" phase for the NewInvocationNode that we create here. Currently only handles no argument VTIs corresponding to a subset of the diagnostic tables. (e.g. lock_table). The node returned is a FROM_VTI node with a passed in NEW_INVOCATION_NODE representing the class, with no arguments. Other attributes of the original FROM_TABLE node (such as resultColumns) are passed into the FROM_VTI node.- Throws:
StandardException
-
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:
getFromTableByNamein classFromTable- 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
-
bindTableDescriptor
private TableDescriptor bindTableDescriptor() throws StandardException
Bind the table descriptor for this table. If the tableName is a synonym, it will be resolved here. The original table name is retained in origTableName.- Throws:
StandardException- Thrown on error
-
bindExpressions
void bindExpressions(FromList fromListParam) throws StandardException
Bind the expressions in this FromBaseTable. This means binding the sub-expressions, as well as figuring out what the return type is for each expression.- Overrides:
bindExpressionsin classResultSetNode- Parameters:
fromListParam- FromList to use/append to.- Throws:
StandardException- Thrown on error
-
bindResultColumns
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:
bindResultColumnsin classResultSetNode- Parameters:
fromListParam- FromList to use/append to.- Throws:
StandardException- Thrown on error
-
getMatchingColumn
ResultColumn getMatchingColumn(ColumnReference columnReference) throws StandardException
Try to find a ResultColumn in the table represented by this FromBaseTable that matches the name in the given ColumnReference.- Overrides:
getMatchingColumnin classResultSetNode- Parameters:
columnReference- The columnReference whose name we're looking for in the given table.- Returns:
- A ResultColumn whose expression is the ColumnNode that matches the ColumnReference. Returns null if there is no match.
- Throws:
StandardException- Thrown on error
-
preprocess
ResultSetNode preprocess(int numTables, GroupByList gbl, FromList fromList) throws StandardException
Preprocess a ResultSetNode - this currently means: o Generating a referenced table map for each ResultSetNode. o Putting the WHERE and HAVING clauses in conjunctive normal form (CNF). o Converting the WHERE and HAVING clauses into PredicateLists and classifying them. o Ensuring that a ProjectRestrictNode is generated on top of every FromBaseTable and generated in place of every FromSubquery. o Pushing single table predicates down to the new ProjectRestrictNodes.- Overrides:
preprocessin classResultSetNode- Parameters:
numTables- The number of tables in the DML Statementgbl- The group by list, if anyfromList- The from list, if any- Returns:
- ResultSetNode at top of preprocessed tree.
- Throws:
StandardException- Thrown on error
-
genProjectRestrict
protected ResultSetNode genProjectRestrict(int numTables) throws StandardException
Put a ProjectRestrictNode on top of each FromTable in the FromList. ColumnReferences must continue to point to the same ResultColumn, so that ResultColumn must percolate up to the new PRN. However, that ResultColumn will point to a new expression, a VirtualColumnNode, which points to the FromTable and the ResultColumn that is the source for the ColumnReference. (The new PRN will have the original of the ResultColumnList and the ResultColumns from that list. The FromTable will get shallow copies of the ResultColumnList and its ResultColumns. ResultColumn.expression will remain at the FromTable, with the PRN getting a new VirtualColumnNode for each ResultColumn.expression.) We then project out the non-referenced columns. If there are no referenced columns, then the PRN's ResultColumnList will consist of a single ResultColumn whose expression is 1.- Overrides:
genProjectRestrictin classResultSetNode- Parameters:
numTables- Number of tables in the DML Statement- Returns:
- The generated ProjectRestrictNode atop the original FromTable.
- Throws:
StandardException- Thrown on error
-
changeAccessPath
ResultSetNode changeAccessPath() throws StandardException
Description copied from class:ResultSetNodeThe 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:
changeAccessPathin classResultSetNode- Returns:
- A ResultSetNode tree modified to do any extra processing for the chosen access path
- Throws:
StandardException- Thrown on error- See Also:
ResultSetNode.changeAccessPath()
-
newResultColumns
private ResultColumnList newResultColumns(ResultColumnList oldColumns, ConglomerateDescriptor idxCD, ConglomerateDescriptor heapCD, boolean cloneRCs) throws StandardException
Create a new ResultColumnList to reflect the columns in the index described by the given ConglomerateDescriptor. The columns in the new ResultColumnList are based on the columns in the given ResultColumnList, which reflects the columns in the base table.- Parameters:
oldColumns- The original list of columns, which reflects the columns in the base table.idxCD- The ConglomerateDescriptor, which describes the index that the new ResultColumnList will reflect.heapCD- The ConglomerateDescriptor for the base heapcloneRCs- Whether or not to clone the RCs- Returns:
- A new ResultColumnList that reflects the columns in the index.
- Throws:
StandardException- Thrown on error
-
generate
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException
Generation on a FromBaseTable creates a scan on the optimizer-selected conglomerate.- Overrides:
generatein classQueryTreeNode- Parameters:
acb- The ActivationClassBuilder for the class being builtmb- the execute() method to be built- Throws:
StandardException- Thrown on error
-
generateResultSet
void generateResultSet(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
Generation on a FromBaseTable for a SELECT. This logic was separated out so that it could be shared with PREPARE SELECT FILTER.- Overrides:
generateResultSetin classResultSetNode- Parameters:
acb- The ExpressionClassBuilder for the class being builtmb- The execute() method to be built- Throws:
StandardException- Thrown on error
-
getFinalCostEstimate
CostEstimate getFinalCostEstimate()
Get the final CostEstimate for this ResultSetNode.- Overrides:
getFinalCostEstimatein classFromTable- Returns:
- The final CostEstimate for this ResultSetNode.
-
pushIndexName
private void pushIndexName(ConglomerateDescriptor cd, MethodBuilder mb) throws StandardException
- Throws:
StandardException
-
generateMaxSpecialResultSet
private void generateMaxSpecialResultSet(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
- Throws:
StandardException
-
generateDistinctScan
private void generateDistinctScan(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
- Throws:
StandardException
-
generateRefActionDependentTableScan
private void generateRefActionDependentTableScan(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
Generation on a FromBaseTable for a referential action dependent table.- Parameters:
acb- The ExpressionClassBuilder for the class being builtmb- The execute() method to be built- Throws:
StandardException- Thrown on error
-
getScanArguments
private int getScanArguments(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException
- Throws:
StandardException
-
mapAbsoluteToRelativeColumnPosition
private int mapAbsoluteToRelativeColumnPosition(int absolutePosition)
Convert an absolute to a relative 0-based column position.- Parameters:
absolutePosition- The absolute 0-based column position.- Returns:
- The relative 0-based column position.
-
getExposedName
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.- Overrides:
getExposedNamein classFromTable- Returns:
- The exposed name of this table.
-
getExposedTableName
TableName getExposedTableName() throws StandardException
Get the exposed table name for this table, which is the name that can be used to refer to it in the rest of the query.- Returns:
- TableName The exposed name of this table.
- Throws:
StandardException- Thrown on error
-
getTableNameField
TableName getTableNameField()
Return the table name for this table.- Returns:
- The table name for this table.
-
getAllResultColumns
ResultColumnList getAllResultColumns(TableName allTableName) 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.- Overrides:
getAllResultColumnsin classResultSetNode- Parameters:
allTableName- The qualifier on the "*"- Returns:
- ResultColumnList List of result columns from this table.
- Throws:
StandardException- Thrown on error
-
genResultColList
ResultColumnList genResultColList() throws StandardException
Build a ResultColumnList based on all of the columns in this FromBaseTable. NOTE - Since the ResultColumnList generated is for the FromBaseTable, ResultColumn.expression will be a BaseColumnNode.- Returns:
- ResultColumnList representing all referenced columns
- Throws:
StandardException- Thrown on error
-
addColsToList
ResultColumnList addColsToList(ResultColumnList inputRcl, FormatableBitSet colsWeWant) throws StandardException
Augment the RCL to include the columns in the FormatableBitSet. If the column is already there, don't add it twice. Column is added as a ResultColumn pointing to a ColumnReference.- Parameters:
inputRcl- The original listcolsWeWant- bit set of cols we want- Returns:
- ResultColumnList the rcl
- Throws:
StandardException- Thrown on error
-
getTableName
TableName getTableName() throws StandardException
Return a TableName node representing this FromTable.- Overrides:
getTableNamein classFromTable- Returns:
- a TableName node representing this FromTable.
- Throws:
StandardException- Thrown on error
-
markAsCursorTargetTable
boolean markAsCursorTargetTable()
Mark this ResultSetNode as the target table of an updatable cursor.- Overrides:
markAsCursorTargetTablein classResultSetNode- Returns:
- true if the target table supports positioned updates.
-
cursorTargetTable
protected boolean cursorTargetTable()
Is this a table that has a FOR UPDATE clause?- Overrides:
cursorTargetTablein classFromTable- Returns:
- true/false
-
markUpdated
void markUpdated(ResultColumnList 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.- Parameters:
updateColumns- A ResultColumnList representing the columns to be updated.
-
referencesTarget
boolean referencesTarget(java.lang.String name, boolean baseTable) throws StandardExceptionSearch to see if a query references the specifed table name.- Overrides:
referencesTargetin classResultSetNode- 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 StandardExceptionReturn true if the node references SESSION schema tables (temporary or permanent)- Overrides:
referencesSessionSchemain classQueryTreeNode- Returns:
- true if references SESSION schema tables, else false
- Throws:
StandardException- Thrown on error
-
isOneRowResultSet
boolean isOneRowResultSet() throws StandardExceptionReturn whether or not the underlying ResultSet tree will return a single row, at most. This method is intended to be used during generation, after the "truly" best conglomerate has been chosen. 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:
isOneRowResultSetin classResultSetNode- Returns:
- Whether or not the underlying ResultSet tree will return a single row.
- Throws:
StandardException- Thrown on error
-
isNotExists
boolean isNotExists()
Return whether or not this is actually a EBT for NOT EXISTS.- Overrides:
isNotExistsin classResultSetNode- Returns:
- Whether or not the underlying ResultSet tree if for NOT EXISTS.
-
isOneRowResultSet
boolean isOneRowResultSet(OptimizablePredicateList predList) throws StandardException
- Throws:
StandardException
-
supersetOfUniqueIndex
protected boolean supersetOfUniqueIndex(boolean[] eqCols) throws StandardExceptionDetermine whether or not the columns marked as true in the passed in array are a superset of any unique index on this table. This is useful for subquery flattening and distinct elimination based on a uniqueness condition.- Parameters:
eqCols- The columns to consider- Returns:
- Whether or not the columns marked as true are a superset
- Throws:
StandardException
-
supersetOfUniqueIndex
protected boolean supersetOfUniqueIndex(JBitSet[] tableColMap) throws StandardException
Determine whether or not the columns marked as true in the passed in join table matrix are a superset of any single column unique index on this table. This is useful for distinct elimination based on a uniqueness condition.- Parameters:
tableColMap- The columns to consider- Returns:
- Whether or not the columns marked as true for one at least one table are a superset
- Throws:
StandardException
-
updateTargetLockMode
int updateTargetLockMode()
Get the lock mode for the target table heap of an update or delete statement. It is not always MODE_RECORD. We want the lock on the heap to be consistent with optimizer and eventually system's decision. This is to avoid deadlock (beetle 4318). During update/delete's execution, it will first use this lock mode we return to lock heap to open a RowChanger, then use the lock mode that is the optimizer and system's combined decision to open the actual source conglomerate. We've got to make sure they are consistent. This is the lock chart (for detail reason, see comments below): BEST ACCESS PATH LOCK MODE ON HEAP ---------------------- ----------------------------------------- index row lock heap row lock if READ_COMMITTED, REPEATBLE_READ, or READ_UNCOMMITTED and not specified table lock otherwise, use optimizer decided best acess path's lock mode- Overrides:
updateTargetLockModein classResultSetNode- Returns:
- The lock mode
- See Also:
TransactionController
-
isOrderedOn
boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, java.util.List<FromBaseTable> fbtHolder) 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. RESOLVE - We do not currently push method calls down, so we don't worry about whether the equals comparisons can be against a variant method.- Overrides:
isOrderedOnin classResultSetNode- Parameters:
crs- The specified ColumnReference[]permuteOrdering- Whether or not the order of the CRs in the array can be permutedfbtHolder- List 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
-
disableBulkFetch
void disableBulkFetch()
Turn off bulk fetch
-
doSpecialMaxScan
void doSpecialMaxScan()
Do a special scan for max.
-
isPossibleDistinctScan
boolean isPossibleDistinctScan(java.util.Set<BaseColumnNode> distinctColumns)
Is it possible to do a distinct scan on this ResultSet tree. (See SelectNode for the criteria.)- Overrides:
isPossibleDistinctScanin classResultSetNode- Parameters:
distinctColumns- the set of distinct columns- 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:
markForDistinctScanin classResultSetNode
-
adjustForSortElimination
void adjustForSortElimination()
Description copied from class:ResultSetNodeNotify the underlying result set tree that the optimizer has chosen to "eliminate" a sort. Sort elimination can happen as part of preprocessing (see esp. SelectNode.preprocess(...)) or it can happen if the optimizer chooses an access path that inherently returns the rows in the correct order (also known as a "sort avoidance" plan). In either case we drop the sort and rely on the underlying result set tree to return its rows in the correct order. For most types of ResultSetNodes we automatically get the rows in the correct order if the sort was eliminated. One exception to this rule, though, is the case of an IndexRowToBaseRowNode, for which we have to disable bulk fetching on the underlying base table. Otherwise the index scan could return rows out of order if the base table is updated while the scan is "in progress" (i.e. while the result set is open). In order to account for this (and potentially other, similar issues in the future) this method exists to notify the result set node that it is expected to return rows in the correct order. The result set can then take necessary action to satsify this requirement--such as disabling bulk fetch in the case of IndexRowToBaseRowNode. All of that said, any ResultSetNodes for which we could potentially eliminate sorts should override this method accordingly. So we don't ever expect to get here.- Overrides:
adjustForSortEliminationin classResultSetNode- See Also:
ResultSetNode.adjustForSortElimination()
-
adjustForSortElimination
void adjustForSortElimination(RequiredRowOrdering rowOrdering) throws StandardException
Description copied from class:ResultSetNodeSame goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed.- Overrides:
adjustForSortEliminationin classResultSetNode- Throws:
StandardException- See Also:
ResultSetNode.adjustForSortElimination()
-
isOrdered
private boolean isOrdered(ColumnReference[] crs, ConglomerateDescriptor cd) throws StandardException
Return whether or not this index is ordered on a permutation of the specified columns.- Parameters:
crs- The specified ColumnReference[]cd- The ConglomerateDescriptor for the chosen index.- Returns:
- Whether or not this index is ordered exactly on the specified columns.
- Throws:
StandardException- Thrown on error
-
isStrictlyOrdered
private boolean isStrictlyOrdered(ColumnReference[] crs, ConglomerateDescriptor cd) throws StandardException
Return whether or not this index is ordered on a permutation of the specified columns.- Parameters:
crs- The specified ColumnReference[]cd- The ConglomerateDescriptor for the chosen index.- Returns:
- Whether or not this index is ordered exactly on the specified columns.
- Throws:
StandardException- Thrown on error
-
isOneRowResultSet
private boolean isOneRowResultSet(ConglomerateDescriptor cd, OptimizablePredicateList predList) throws StandardException
Is this a one-row result set with the given conglomerate descriptor?- Throws:
StandardException
-
getDefaultBulkFetch
private int getDefaultBulkFetch() throws StandardException- Throws:
StandardException
-
getUserSpecifiedIndexName
private java.lang.String getUserSpecifiedIndexName()
-
getStoreCostController
private StoreCostController getStoreCostController(ConglomerateDescriptor cd) throws StandardException
- Throws:
StandardException
-
getBaseCostController
private StoreCostController getBaseCostController() throws StandardException
- Throws:
StandardException
-
baseRowCount
private long baseRowCount() throws StandardException- Throws:
StandardException
-
getRowTemplate
private DataValueDescriptor[] getRowTemplate(ConglomerateDescriptor cd, StoreCostController scc) throws StandardException
- Throws:
StandardException
-
getFirstConglom
private ConglomerateDescriptor getFirstConglom() throws StandardException
- Throws:
StandardException
-
getNextConglom
private ConglomerateDescriptor getNextConglom(ConglomerateDescriptor currCD)
-
getConglomDescs
private void getConglomDescs() throws StandardException- Throws:
StandardException
-
setRefActionInfo
void setRefActionInfo(long fkIndexConglomId, int[] fkColArray, java.lang.String parentResultSetId, boolean dependentScan)set the Information gathered from the parent table that is required to perform a referential action on dependent table.- Overrides:
setRefActionInfoin classQueryTreeNode
-
acceptChildren
void acceptChildren(Visitor v) throws StandardException
Accept the visitor for all visitable children of this node.- Overrides:
acceptChildrenin classFromTable- Parameters:
v- the visitor- Throws:
StandardException- on error
-
qualifiesForStatisticsUpdateCheck
private boolean qualifiesForStatisticsUpdateCheck(TableDescriptor td) throws StandardException
Tells if the given table qualifies for a statistics update check in the current configuration.- Parameters:
td- the table to check- Returns:
trueif qualified,falseif not- Throws:
StandardException
-
-