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

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.ResultSetNode
          extended by org.apache.derby.impl.sql.compile.FromTable
              extended by org.apache.derby.impl.sql.compile.IndexToBaseRowNode
All Implemented Interfaces:
Optimizable, Visitable

public class IndexToBaseRowNode
extends FromTable

This node type translates an index row to a base row. It takes a FromBaseTable as its source ResultSetNode, and generates an IndexRowToBaseRowResultSet that takes a TableScanResultSet on an index conglomerate as its source.


Field Summary
private  FormatableBitSet allReferencedCols
           
protected  ConglomerateDescriptor baseCD
           
protected  boolean cursorTargetTable
           
protected  boolean forUpdate
           
private  FormatableBitSet heapOnlyReferencedCols
           
private  FormatableBitSet heapReferencedCols
           
private  FormatableBitSet indexReferencedCols
           
protected  PredicateList restrictionList
           
protected  FromBaseTable source
           
 
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.ResultSetNode
costEstimate, finalCostEstimate, insertSource, optimizer, referencedTableMap, resultColumns, resultSetNumber, scratchCostEstimate, statementResultSet
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
IndexToBaseRowNode()
           
 
Method Summary
(package private)  void acceptChildren(Visitor v)
          Accept the visitor for all visitable children of this node.
(package private)  void adjustForSortElimination()
          Notify the underlying result set tree that the optimizer has chosen to "eliminate" a sort.
(package private)  void adjustForSortElimination(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.
(package private)  void decrementLevel(int decrement)
          Decrement (query block) level (0-based) for this FromTable.
 boolean forUpdate()
          Return true if this is the target table of an update
 void generate(ActivationClassBuilder acb, MethodBuilder mb)
          Generation of an IndexToBaseRowNode creates an IndexRowToBaseRowResultSet, which uses the RowLocation in the last column of an index row to get the row from the base conglomerate (heap).
 CostEstimate getCostEstimate()
          Get the CostEstimate for this ResultSetNode.
 CostEstimate getFinalCostEstimate()
          Get the final CostEstimate for this FromTable.
private  int[] getIndexColMapping()
          Fill in the column mapping for those columns coming from the index.
 AccessPath getTrulyTheBestAccessPath()
          Get the best access path overall for this Optimizable.
 void init(java.lang.Object source, java.lang.Object baseCD, java.lang.Object resultColumns, java.lang.Object cursorTargetTable, java.lang.Object heapReferencedCols, java.lang.Object indexReferencedCols, java.lang.Object restrictionList, java.lang.Object forUpdate, java.lang.Object tableProperties)
          Initialize a query tree node.
 boolean isNotExists()
          Return whether or not the underlying FBT is for NOT EXISTS.
 boolean isOneRowResultSet()
          Return whether or not the underlying ResultSet tree will return a single row, at most.
(package private)  boolean isOrderedOn(ColumnReference[] crs, boolean permuteOrdering, java.util.Vector fbtVector)
          Return whether or not the underlying ResultSet tree is ordered on the specified columns.
 int updateTargetLockMode()
          Get the lock mode for the target of an update statement (a delete or update).
 
Methods inherited from class org.apache.derby.impl.sql.compile.FromTable
assignCostEstimate, canBeOrdered, considerSortAvoidancePath, convertAbsoluteToRelativeColumnPosition, cursorTargetTable, estimateCost, feasibleJoinStrategy, fillInReferencedTableMap, flatten, getBaseTableName, getBestAccessPath, getBestSortAvoidancePath, getCorrelationName, getCostEstimate, getCurrentAccessPath, getExposedName, getFromTableByName, getLevel, getName, getNumColumnsReturned, getOrigTableName, getProperties, getResultColumnsForList, getSchemaDescriptor, getSchemaDescriptor, getScratchCostEstimate, getTableDescriptor, getTableName, getTableNumber, getUserSpecifiedJoinStrategy, hashKeyColumns, hasTableNumber, init, initAccessPaths, initialCapacity, isBaseTable, isCoveringIndex, isFlattenableJoinNode, isMaterializable, isOneRowScan, isTargetTable, legalJoinOrder, loadFactor, LOJ_reorderable, markUpdatableByCursor, maxCapacity, memoryUsageOK, modifyAccessPath, needsSpecialRCLBinding, nextAccessPath, optimizeIt, optimizeSubqueries, pullOptPredicates, pushExpressions, pushOptPredicate, rememberAsBest, rememberJoinStrategyAsBest, rememberSortAvoidancePath, resetJoinStrategies, setCostEstimate, setHashKeyColumns, setLevel, setOrigTableName, setProperties, setTableNumber, startOptimizing, supportsMultipleInstantiations, tellRowOrderingAboutConstantColumns, toString, transformOuterJoins, uniqueJoin, updateBestPlanMap, verifyProperties
 
Methods inherited from class org.apache.derby.impl.sql.compile.ResultSetNode
addNewPredicate, assignResultSetNumber, bindExpressions, bindExpressionsWithTables, bindNonVTITables, bindResultColumns, bindResultColumns, bindTargetExpressions, bindUntypedNullsToResultColumns, bindVTITables, changeAccessPath, columnTypesAndLengthsMatch, considerMaterialization, disablePrivilegeCollection, enhanceRCLForInsert, ensurePredicateList, flattenableInFromSubquery, generateNormalizationResultSet, generateResultSet, genProjectRestrict, genProjectRestrict, genProjectRestrictForReordering, getAllResultColumns, getCursorTargetTable, getFromList, getMatchingColumn, getNewCostEstimate, getOptimizer, getOptimizerImpl, getRCLForInsert, getReferencedTableMap, getResultColumns, getResultSetNumber, isPossibleDistinctScan, isUpdatableCursor, LOJgetReferencedTables, makeResultDescription, makeResultDescriptors, markAsCursorTargetTable, markForDistinctScan, markStatementResultSet, modifyAccessPaths, modifyAccessPaths, notCursorTargetTable, notFlattenableJoin, numDistinctAggregates, optimize, parseDefault, performMaterialization, preprocess, printSubNodes, projectResultColumns, pushOffsetFetchFirst, pushOrderByList, referencesTarget, rejectParameters, rejectXMLValues, renameGeneratedResultNames, replaceOrForbidDefaults, returnsAtMostOneRow, setInsertSource, setReferencedTableMap, setResultColumns, setResultToBooleanTrueNode, setTableConstructorTypes, subqueryReferencesTarget, verifySelectStarSubquery
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.sql.compile.Optimizable
getDataDictionary, getReferencedTableMap, getResultSetNumber
 

Field Detail

source

protected FromBaseTable source

baseCD

protected ConglomerateDescriptor baseCD

cursorTargetTable

protected boolean cursorTargetTable

restrictionList

protected PredicateList restrictionList

forUpdate

protected boolean forUpdate

heapReferencedCols

private FormatableBitSet heapReferencedCols

indexReferencedCols

private FormatableBitSet indexReferencedCols

allReferencedCols

private FormatableBitSet allReferencedCols

heapOnlyReferencedCols

private FormatableBitSet heapOnlyReferencedCols
Constructor Detail

IndexToBaseRowNode

public IndexToBaseRowNode()
Method Detail

init

public void init(java.lang.Object source,
                 java.lang.Object baseCD,
                 java.lang.Object resultColumns,
                 java.lang.Object cursorTargetTable,
                 java.lang.Object heapReferencedCols,
                 java.lang.Object indexReferencedCols,
                 java.lang.Object restrictionList,
                 java.lang.Object forUpdate,
                 java.lang.Object tableProperties)
Description copied from class: QueryTreeNode
Initialize a query tree node.

Overrides:
init in class QueryTreeNode

forUpdate

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

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

getTrulyTheBestAccessPath

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

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

getCostEstimate

public CostEstimate getCostEstimate()
Description copied from class: ResultSetNode
Get the CostEstimate for this ResultSetNode.

Overrides:
getCostEstimate in class ResultSetNode
Returns:
The CostEstimate for this ResultSetNode.

getFinalCostEstimate

public CostEstimate getFinalCostEstimate()
Description copied from class: FromTable
Get the final CostEstimate for this FromTable.

Overrides:
getFinalCostEstimate in class FromTable
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.

isOrderedOn

boolean isOrderedOn(ColumnReference[] crs,
                    boolean permuteOrdering,
                    java.util.Vector fbtVector)
              throws StandardException
Return whether or not the underlying ResultSet tree is ordered on the specified columns. RESOLVE - This method currently only considers the outermost table of the query block.

Overrides:
isOrderedOn in class ResultSetNode
Parameters:
crs - The specified ColumnReference[]
permuteOrdering - Whether or not the order of the CRs in the array can be permuted
fbtVector - Vector that is to be filled with the FromBaseTable
Returns:
Whether the underlying ResultSet tree is ordered on the specified column.
Throws:
StandardException - Thrown on error

generate

public void generate(ActivationClassBuilder acb,
                     MethodBuilder mb)
              throws StandardException
Generation of an IndexToBaseRowNode creates an IndexRowToBaseRowResultSet, which uses the RowLocation in the last column of an index row to get the row from the base conglomerate (heap).

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

isOneRowResultSet

public boolean isOneRowResultSet()
                          throws StandardException
Return whether or not the underlying ResultSet tree will return a single row, at most. This is important for join nodes where we can save the extra next on the right side if we know that it will return at most 1 row.

Overrides:
isOneRowResultSet in class ResultSetNode
Returns:
Whether or not the underlying ResultSet tree will return a single row.
Throws:
StandardException - Thrown on error

isNotExists

public boolean isNotExists()
Return whether or not the underlying FBT is for NOT EXISTS.

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

decrementLevel

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

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

updateTargetLockMode

public int updateTargetLockMode()
Get the lock mode for the target of an update statement (a delete or update). The update mode will always be row for CurrentOfNodes. It will be table if there is no where clause.

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

adjustForSortElimination

void adjustForSortElimination()
Description copied from class: ResultSetNode
Notify 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:
adjustForSortElimination in class ResultSetNode
See Also:
ResultSetNode.adjustForSortElimination()

adjustForSortElimination

void adjustForSortElimination(RequiredRowOrdering rowOrdering)
                        throws StandardException
Description copied from class: ResultSetNode
Same goal as adjustForSortElimination above, but this version takes a RequiredRowOrdering to allow nodes to adjust based on the ORDER BY clause, if needed.

Overrides:
adjustForSortElimination in class ResultSetNode
Throws:
StandardException
See Also:
ResultSetNode.adjustForSortElimination()

getIndexColMapping

private int[] getIndexColMapping()
Fill in the column mapping for those columns coming from the index.

Returns:
The int[] with the mapping.

acceptChildren

void acceptChildren(Visitor v)
              throws StandardException
Accept the visitor for all visitable children of this node.

Overrides:
acceptChildren in class ResultSetNode
Parameters:
v - the visitor
Throws:
StandardException - on error

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.