Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv abstract Class FromTable

extends ResultSetNode
implements Optimizable
Class Inheritance
All Implemented Interfaces
org.apache.derby.iapi.sql.compile.Optimizable, org.apache.derby.iapi.sql.compile.Visitable
Known Direct Subclasses
org.apache.derby.impl.sql.compile.FromVTI, org.apache.derby.impl.sql.compile.IndexToBaseRowNode, org.apache.derby.impl.sql.compile.RowResultSetNode, org.apache.derby.impl.sql.compile.SingleChildResultSetNode, org.apache.derby.impl.sql.compile.TableOperatorNode, org.apache.derby.impl.sql.compile.CurrentOfNode, org.apache.derby.impl.sql.compile.FromBaseTable, org.apache.derby.impl.sql.compile.FromSubquery
Imports
java.util.Enumeration, .HashMap, .List, .Properties, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.AccessPath, .CostEstimate, .JoinStrategy, .Optimizable, .OptimizablePredicate, .OptimizablePredicateList, .Optimizer, .RowOrdering, .Visitor, org.apache.derby.iapi.sql.dictionary.*, org.apache.derby.iapi.types.DataTypeDescriptor, org.apache.derby.iapi.util.JBitSet, .StringUtil, org.apache.derby.impl.sql.execute.HashScanResultSet

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

Field Summary

Modifier and TypeField and Description
private int
_mergeTableID

for resolving column references in MERGE statements in tough cases

protected static final short
pack-priv AccessPathImpl
protected CostEstimate
private HashMap<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.

pack-priv AccessPathImpl
private boolean
pack-priv String
pack-priv TableName
pack-priv AccessPathImpl
pack-priv int[]
pack-priv int
private int
pack-priv int
protected static final short
pack-priv float
pack-priv int
protected TableName
origTableName

the original unbound table name

private double
protected static final short
REMOVE_PLAN

Operations that can be performed on bestPlanMap.

pack-priv int
pack-priv Properties
pack-priv AccessPathImpl
protected String

Constructor Summary

AccessConstructor and Description
pack-priv
FromTable(String
The correlation name
correlationName
,
Properties
Properties list associated with the table
tableProperties
,
ContextManager
The context manager
cm
)

Constructor for a table in a FROM list.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.acceptChildren.

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

pack-priv boolean

Returns:

true if some columns in this table are updatable.
columnsAreUpdatable
()

Return true if some columns in this table are updatable.

public boolean
considerSortAvoidancePath()

Implements org.apache.derby.iapi.sql.compile.Optimizable.considerSortAvoidancePath.

Check whether this optimizable's sort avoidance path should be considered.

public int
convertAbsoluteToRelativeColumnPosition(int
The absolute 0-based column position for the column.
absolutePosition
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.convertAbsoluteToRelativeColumnPosition.

Convert an absolute to a relative 0-based column position.

protected boolean

Returns:

true/false
cursorTargetTable
()

Is this a table that has a FOR UPDATE clause.

pack-priv void
decrementLevel(int
The amount to decrement by.
decrement
)

Implements abstract org.apache.derby.impl.sql.compile.ResultSetNode.decrementLevel.

Decrement (query block) level (0-based) for this FromTable.

public CostEstimate
estimateCost(OptimizablePredicateList
The predicate list to optimize against
predList
,
ConglomerateDescriptor
The conglomerate descriptor to get the cost of
cd
,
CostEstimate
The estimated cost of the part of the plan outer to this optimizable.
outerCost
,
Optimizer
The optimizer to use to help estimate the cost
optimizer
,
RowOrdering
The row ordering for all the tables in the join order, including this one.
rowOrdering
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.estimateCost.

Estimate the cost of scanning this Optimizable using the given predicate list with the given conglomerate.

public boolean
feasibleJoinStrategy(OptimizablePredicateList
The predicate list that has been pushed down to this optimizable
predList
,
Optimizer
The optimizer to use.
optimizer
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.feasibleJoinStrategy.

Is the current proposed join strategy for this optimizable feasible given the predicate list?

pack-priv void
fillInReferencedTableMap(JBitSet
The table map to fill in.
passedMap
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.fillInReferencedTableMap.

Fill the referencedTableMap with this ResultSetNode.

pack-priv FromList

Returns:

FromList The fromList from the underlying SelectNode.
flatten
(ResultColumnList
The RCL from the outer query
rcl
,
PredicateList
PredicateList to append wherePredicates to.
outerPList
,
SubqueryList
The SubqueryList from the outer query
sql
,
GroupByList
The group by list, if any
gbl
,
ValueNode
The HAVING clause, if any
havingClause
)

Flatten this FromTable into the outer query block.

public boolean
forUpdate()

Implements org.apache.derby.iapi.sql.compile.Optimizable.forUpdate.

Return true if this is the target table of an update

public String
getBaseTableName()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getBaseTableName.

Get the table name of this Optimizable.

public AccessPath
getBestAccessPath()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getBestAccessPath.

Get the best access path for this Optimizable.

public AccessPath
getBestSortAvoidancePath()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getBestSortAvoidancePath.

Get the best sort-avoidance path for this Optimizable.

public String
getCorrelationName()

Get this table's correlation name, if any.

protected CostEstimate
public AccessPath
getCurrentAccessPath()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getCurrentAccessPath.

Get the current access path under consideration for this Optimizable

pack-priv String

Returns:

The exposed name of this table.
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.

pack-priv CostEstimate

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

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getFinalCostEstimate.

Get the final CostEstimate for this FromTable.

pack-priv FromTable

Returns:

The FromTable, if any, with the exposed name.
getFromTableByName
(String
The specified name to search for as an exposed name.
name
,
String
Schema name, if non-null.
schemaName
,
boolean
Whether or not we need an exact match on specified schema and table names or match on table id.
exactMatch
)

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.getFromTableByName.

Determine whether or not the specified name is an exposed name in the current query block.

pack-priv int

Returns:

int The query block level for this FromTable.
getLevel
()

Get the (query block) level (0-based) for this FromTable.

pack-priv int
getMergeTableID()

get the merge table id

public String
getName()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getName.

Get the (exposed) name of this Optimizable

public int
getNumColumnsReturned()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getNumColumnsReturned.

Get the number of the number of columns returned by this Optimizable.

pack-priv TableName

Returns:

TableName the original or unbound tablename
getOrigTableName
()

Gets the original or unbound table name for this FromTable.

private double
public Properties
getProperties()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getProperties.

Get the Properties list, if any, associated with this optimizable.

pack-priv ResultColumnList

Returns:

ResultColumnList List of result columns from this table.
getResultColumnsForList
(TableName
The qualifier on the "*"
allTableName
,
ResultColumnList inputRcl, TableName tableName)

Return a ResultColumnList with all of the columns in this table.

pack-priv SchemaDescriptor

Returns:

Schema Descriptor
getSchemaDescriptor
()

Get a schema descriptor for the given table.

pack-priv SchemaDescriptor

Returns:

Schema Descriptor
getSchemaDescriptor
(TableName
the table name
tableName
)

Get a schema descriptor for the given table.

protected CostEstimate
public TableDescriptor
getTableDescriptor()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getTableDescriptor.

Get the table descriptor for this table (if any).

pack-priv TableName

Returns:

a TableName node representing this FromTable.
getTableName
()

Return a TableName node representing this FromTable.

public int
getTableNumber()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getTableNumber.

Get this Optimizable's table number

public AccessPath
getTrulyTheBestAccessPath()

Implements org.apache.derby.iapi.sql.compile.Optimizable.getTrulyTheBestAccessPath.

Get the best access path overall for this Optimizable.

pack-priv String

Returns:

The user specified join strategy, if any for this table.
getUserSpecifiedJoinStrategy
()

Return the user specified join strategy, if any for this table.

public int[]
hashKeyColumns()

Implements org.apache.derby.iapi.sql.compile.Optimizable.hashKeyColumns.

Return the hash key column numbers, for hash join strategy

public boolean

Returns:

true if at least one large object column is referenced, false otherwise
hasLargeObjectColumns
()

Implements org.apache.derby.iapi.sql.compile.Optimizable.hasLargeObjectColumns.

Check if any columns containing large objects (BLOBs or CLOBs) are referenced in this table.

public boolean
hasTableNumber()

Implements org.apache.derby.iapi.sql.compile.Optimizable.hasTableNumber.

Return true if this Optimizable has a table number

public void
initAccessPaths(Optimizer
The optimizer being used.
optimizer
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.initAccessPaths.

Init the access paths for this optimizable.

public int
initialCapacity()

Implements org.apache.derby.iapi.sql.compile.Optimizable.initialCapacity.

Return the initial capacity of the hash table, for hash join strategy

public boolean
isBaseTable()

Implements org.apache.derby.iapi.sql.compile.Optimizable.isBaseTable.

Tell whether this Optimizable represents a base table

public boolean
isCoveringIndex(ConglomerateDescriptor
ConglomerateDesriptor for index to consider
cd
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.isCoveringIndex.

Return whether or not this is a covering index.

pack-priv boolean

Returns:

boolean Whether or not this FromTable can be flattened.
isFlattenableJoinNode
()

Is this FromTable a JoinNode which can be flattened into the parents FromList.

pack-priv void
public boolean
isMaterializable()

Implements org.apache.derby.iapi.sql.compile.Optimizable.isMaterializable.

Tell whether this Optimizable is materializable

public boolean
isOneRowScan()

Implements org.apache.derby.iapi.sql.compile.Optimizable.isOneRowScan.

Will the optimizable return at most 1 row per scan?

public boolean
isTargetTable()

Implements org.apache.derby.iapi.sql.compile.Optimizable.isTargetTable.

Is the optimizable the target table of an update or delete?

public boolean
legalJoinOrder(JBitSet
The tables that have been placed so far in the join order.
assignedTableMap
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.legalJoinOrder.

Can this Optimizable appear at the current location in the join order.

public float
loadFactor()

Implements org.apache.derby.iapi.sql.compile.Optimizable.loadFactor.

Return the load factor of the hash table, for hash join strategy

pack-priv boolean
LOJ_reorderable(int numTables)

no LOJ reordering for this FromTable.

protected void
markUpdatableByCursor(List<String>
A list representing the columns that can be updated.
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.

public int
maxCapacity(JoinStrategy joinStrategy, int
The maximum number of bytes to be used. Ignored if the user has set a maximum number of rows for the Optimizable.
maxMemoryPerTable
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.maxCapacity.

Return the maximum capacity of the hash table, for hash join strategy

public boolean
memoryUsageOK(double rowCount, int maxMemoryPerTable)

Implements org.apache.derby.iapi.sql.compile.Optimizable.memoryUsageOK.

public Optimizable
modifyAccessPath(JBitSet
Bit map of the tables that are outer to this one in the join order.
outerTables
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.modifyAccessPath.

Modify the access path for this Optimizable, as necessary.

pack-priv boolean
public boolean
nextAccessPath(Optimizer
Optimizer to use.
optimizer
,
OptimizablePredicateList
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.
predList
,
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.
rowOrdering
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.nextAccessPath.

Choose the next access path to evaluate for this Optimizable.

public CostEstimate
optimizeIt(Optimizer
Optimizer to use.
optimizer
,
OptimizablePredicateList
The predicate list to optimize against
predList
,
CostEstimate
The CostEstimate for the outer tables in the join order, telling how many times this Optimizable will be scanned.
outerCost
,
RowOrdering
The row ordering for all the tables in the join order, including this one.
rowOrdering
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.optimizeIt.

Choose the best access path for this Optimizable.

pack-priv void
optimizeSubqueries(DataDictionary dd, double rowCount)

Optimize any subqueries that haven't been optimized any where else.

public void
pullOptPredicates(OptimizablePredicateList
The list to put the pulled predicates in.
optimizablePredicates
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.pullOptPredicates.

Pull all the OptimizablePredicates from this Optimizable and put them in the given OptimizablePredicateList.

pack-priv void
pushExpressions(PredicateList
The PredicateList.
predicateList
)

Push expressions down to the first ResultSetNode which can do expression evaluation and has the same referenced table map.

public boolean
pushOptPredicate(OptimizablePredicate
OptimizablePredicate to push down.
optimizablePredicate
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.pushOptPredicate.

Push an OptimizablePredicate down, if this node accepts it.

public void
rememberAsBest(int
The type of plan (one of Optimizer.NORMAL_PLAN or Optimizer.SORT_AVOIDANCE_PLAN)
planType
,
Optimizer
The OptimizerImpl that is telling this Optimizable to remember its current path as "truly the best".
optimizer
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.rememberAsBest.

Remember the current access path as the best one (so far).

public void
rememberJoinStrategyAsBest(AccessPath ap)

Implements org.apache.derby.iapi.sql.compile.Optimizable.rememberJoinStrategyAsBest.

Remember the current join strategy as the best one so far in this join order.

public void
rememberSortAvoidancePath()

Implements org.apache.derby.iapi.sql.compile.Optimizable.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.

public void
setHashKeyColumns(int[] columnNumbers)

Implements org.apache.derby.iapi.sql.compile.Optimizable.setHashKeyColumns.

Set the hash key column numbers, for hash join strategy

pack-priv void
setLevel(int
The query block level for this FromTable.
level
)

Set the (query block) level (0-based) for this FromTable.

pack-priv void
setMergeTableID(int mergeTableID)

set the merge table id

pack-priv void
setOrigTableName(TableName
the unbound table name
tableName
)

Sets the original or unbound table name for this FromTable.

public void
setProperties(Properties
The Properties list for this optimizable.
tableProperties
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.setProperties.

Set the Properties list for this optimizalbe.

pack-priv void
setTableNumber(int
The table # for this table.
tableNumber
)

Set the table # for this table.

public void
startOptimizing(Optimizer optimizer, RowOrdering rowOrdering)

Implements org.apache.derby.iapi.sql.compile.Optimizable.startOptimizing.

Begin the optimization process for this Optimizable.

public boolean
supportsMultipleInstantiations()

Implements org.apache.derby.iapi.sql.compile.Optimizable.supportsMultipleInstantiations.

Tell whether this Optimizable can be instantiated multiple times

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.

public String

Returns:

This object as a String
toString
()

Overrides org.apache.derby.impl.sql.compile.ResultSetNode.toString.

Convert this object to a String.

pack-priv FromTable

Returns:

The new tree top (OuterJoin or InnerJoin).
transformOuterJoins
(ValueNode
The predicate tree for the query block
predicateTree
,
int numTables)

Transform any Outer Join into an Inner Join where applicable.

public double
uniqueJoin(OptimizablePredicateList
The predicate list to check
predList
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.uniqueJoin.

Does this optimizable have a uniqueness condition on the given predicate list, and if so, how many unique keys will be returned per scan.

public void
updateBestPlanMap(short
Indicates whether we're adding, loading, or removing a best plan for the OptimizerImpl/Optimizable.
action
,
Object
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.
planKey
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.updateBestPlanMap.

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.

public void
verifyProperties(DataDictionary
The DataDictionary to use.
dDictionary
)

Implements org.apache.derby.iapi.sql.compile.Optimizable.verifyProperties.

Verify that the Properties list with optimizer overrides, if specified, is valid

Inherited from org.apache.derby.impl.sql.compile.ResultSetNode:
addNewPredicateadjustForSortEliminationadjustForSortEliminationassignResultSetNumberbindExpressionsbindExpressionsWithTablesbindNonVTITablesbindResultColumnsbindResultColumnsbindTargetExpressionsbindUntypedNullsToResultColumnsbindVTITableschangeAccessPathcolumnTypesAndLengthsMatchconsiderMaterializationenhanceRCLForInsertensurePredicateListflattenableInFromSubquerygenerateNormalizationResultSetgenerateResultSetgenProjectRestrictgenProjectRestrictgenProjectRestrictForReorderinggetAllResultColumnsgetCandidateFinalCostEstimategetCostEstimategetCursorTargetTablegetFromListgetMatchingColumngetNewCostEstimategetOptimizergetOptimizerImplgetRCLForInsertgetReferencedTableMapgetResultColumnsgetResultSetNumbergetScratchCostEstimateisCursorTargetTableisInsertSourceisNotExistsisOneRowResultSetisOrderedOnisPossibleDistinctScanisStatementResultSetisUpdatableCursorLOJgetReferencedTablesmakeResultDescriptionmakeResultDescriptorsmarkAsCursorTargetTablemarkForDistinctScanmarkStatementResultSetmodifyAccessPathsmodifyAccessPathsnotCursorTargetTablenotFlattenableJoinnumDistinctAggregatesoptimizeparseDefaultperformMaterializationpreprocessprintQueryExpressionSuffixClausesprintSubNodesprojectResultColumnspushOffsetFetchFirstpushOrderByListpushQueryExpressionSuffixreferencesTargetrejectParametersrejectXMLValuesrenameGeneratedResultNamesreplaceOrForbidDefaultsreturnsAtMostOneRowsetCandidateFinalCostEstimatesetCostEstimatesetCursorTargetTablesetInsertSourcesetOptimizersetReferencedTableMapsetResultColumnssetResultSetNumbersetResultToBooleanTrueNodesetScratchCostEstimatesetTableConstructorTypessubqueryReferencesTargetupdateTargetLockModeverifySelectStarSubquery