|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> sql >> [ compile overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.impl.sql.compile
Class OptimizerImpl

java.lang.Objectorg.apache.derby.impl.sql.compile.OptimizerImpl
- All Implemented Interfaces:
- org.apache.derby.iapi.sql.compile.Optimizer
- Direct Known Subclasses:
- Level2OptimizerImpl
- public class OptimizerImpl
- extends java.lang.Object
- implements org.apache.derby.iapi.sql.compile.Optimizer
- extends java.lang.Object
This will be the Level 1 Optimizer. RESOLVE - it's a level 0 optimizer right now. Current State: o No costing services o We can only cost a derived table with a join once. Optimizer uses OptimizableList to keep track of the best join order as it builds it. For each available slot in the join order, we cost all of the Optimizables from that slot til the end of the OptimizableList. Later, we will choose the best Optimizable for that slot and reorder the list accordingly. In order to do this, we probably need to move the temporary pushing and pulling of join clauses into Optimizer, since the logic will be different for other implementations. (Of course, we're not pushing and pulling join clauses between permutations yet.)
| Constructor Summary | |
protected |
OptimizerImpl(org.apache.derby.iapi.sql.compile.OptimizableList optimizableList,
org.apache.derby.iapi.sql.compile.OptimizablePredicateList predicateList,
org.apache.derby.iapi.sql.dictionary.DataDictionary dDictionary,
boolean ruleBasedOptimization,
boolean noTimeout,
boolean useStatistics,
int maxMemoryPerTable,
org.apache.derby.iapi.sql.compile.JoinStrategy[] joinStrategies,
int tableLockThreshold,
org.apache.derby.iapi.sql.compile.RequiredRowOrdering requiredRowOrdering,
int numTablesInQuery)
|
| Method Summary | |
void |
considerCost(org.apache.derby.iapi.sql.compile.Optimizable optimizable,
org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList,
org.apache.derby.iapi.sql.compile.CostEstimate estimatedCost,
org.apache.derby.iapi.sql.compile.CostEstimate outerCost)
This is the version of costOptimizable for non-base-tables. |
private void |
costBasedCostOptimizable(org.apache.derby.iapi.sql.compile.Optimizable optimizable,
org.apache.derby.iapi.sql.dictionary.TableDescriptor td,
org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd,
org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList,
org.apache.derby.iapi.sql.compile.CostEstimate outerCost)
This method decides whether the given conglomerate descriptor is cheapest based on cost, rather than based on rules. |
void |
costOptimizable(org.apache.derby.iapi.sql.compile.Optimizable optimizable,
org.apache.derby.iapi.sql.dictionary.TableDescriptor td,
org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd,
org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList,
org.apache.derby.iapi.sql.compile.CostEstimate outerCost)
Cost the current Optimizable with the specified OPL. |
void |
costPermutation()
Cost the current permutation. |
private org.apache.derby.iapi.sql.compile.CostEstimate |
estimateTotalCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList,
org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd,
org.apache.derby.iapi.sql.compile.CostEstimate outerCost,
org.apache.derby.iapi.sql.compile.Optimizable optimizable)
Estimate the total cost of doing a join with the given optimizable. |
org.apache.derby.iapi.sql.dictionary.DataDictionary |
getDataDictionary()
Return the DataDictionary that the Optimizer is using. |
org.apache.derby.iapi.sql.compile.JoinStrategy |
getJoinStrategy(int whichStrategy)
Gets a join strategy by number (zero-based). |
org.apache.derby.iapi.sql.compile.JoinStrategy |
getJoinStrategy(java.lang.String whichStrategy)
Gets a join strategy by name. |
int |
getLevel()
Get the level of this optimizer. |
int |
getMaxMemoryPerTable()
|
CostEstimateImpl |
getNewCostEstimate(double theCost,
double theRowCount,
double theSingleScanRowCount)
|
boolean |
getNextDecoratedPermutation()
Iterate through the "decorated permutations", returning false when they are exhausted. |
boolean |
getNextPermutation()
Iterate through the permutations, returning false when the permutations are exhausted. |
int |
getNumberOfJoinStrategies()
Get the number of join strategies supported by this optimizer. |
org.apache.derby.iapi.sql.compile.CostEstimate |
getOptimizedCost()
Get the estimated cost of the optimized query |
private boolean |
isPushable(org.apache.derby.iapi.sql.compile.OptimizablePredicate pred)
|
void |
modifyAccessPaths()
Modify the access path for each Optimizable, as necessary. |
org.apache.derby.iapi.sql.compile.CostEstimate |
newCostEstimate()
Get a new CostEstimate object |
(package private) void |
pushPredicates(org.apache.derby.iapi.sql.compile.Optimizable curTable,
org.apache.derby.iapi.util.JBitSet outerTables)
|
private void |
rememberBestCost(org.apache.derby.iapi.sql.compile.CostEstimate currentCost,
int planType)
Is the cost of this join order lower than the best one we've found so far? If so, remember it. |
private void |
rewindJoinOrder()
|
private void |
ruleBasedCostOptimizable(org.apache.derby.iapi.sql.compile.Optimizable optimizable,
org.apache.derby.iapi.sql.dictionary.TableDescriptor td,
org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd,
org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList,
org.apache.derby.iapi.sql.compile.CostEstimate outerCost)
This method decides whether the given conglomerate descriptor is cheapest based on rules, rather than based on cost estimates. |
void |
setOuterRows(double outerRows)
Set the estimated number of outer rows - good for optimizing nested optimizables like subqueries and join nodes. |
int |
tableLockThreshold()
Get the maximum number of estimated rows touched in a table before we decide to open the table with table locking (as opposed to row locking. |
void |
trace(int traceFlag,
int intParam1,
int intParam2,
double doubleParam,
java.lang.Object objectParam1)
Optimizer trace. |
double |
uniqueJoinWithOuterTable(org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList)
Tells whether any of the tables outer to the current one has a uniqueness condition on the given predicate list, and if so, how many times each unique key can be seen by the current table. |
boolean |
useStatistics()
If statistics should be considered by the optimizer while optimizing a query. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
dDictionary
org.apache.derby.iapi.sql.dictionary.DataDictionary dDictionary
numTablesInQuery
int numTablesInQuery
numOptimizables
int numOptimizables
assignedTableMap
protected org.apache.derby.iapi.util.JBitSet assignedTableMap
optimizableList
protected org.apache.derby.iapi.sql.compile.OptimizableList optimizableList
predicateList
org.apache.derby.iapi.sql.compile.OptimizablePredicateList predicateList
nonCorrelatedTableMap
org.apache.derby.iapi.util.JBitSet nonCorrelatedTableMap
proposedJoinOrder
protected int[] proposedJoinOrder
bestJoinOrder
protected int[] bestJoinOrder
joinPosition
protected int joinPosition
desiredJoinOrderFound
boolean desiredJoinOrderFound
NO_JUMP
private static final int NO_JUMP
- See Also:
- Constant Field Values
READY_TO_JUMP
private static final int READY_TO_JUMP
- See Also:
- Constant Field Values
JUMPING
private static final int JUMPING
- See Also:
- Constant Field Values
WALK_HIGH
private static final int WALK_HIGH
- See Also:
- Constant Field Values
WALK_LOW
private static final int WALK_LOW
- See Also:
- Constant Field Values
permuteState
private int permuteState
firstLookOrder
private int[] firstLookOrder
ruleBasedOptimization
private boolean ruleBasedOptimization
outermostCostEstimate
private CostEstimateImpl outermostCostEstimate
currentCost
protected CostEstimateImpl currentCost
currentSortAvoidanceCost
protected CostEstimateImpl currentSortAvoidanceCost
bestCost
protected CostEstimateImpl bestCost
timeOptimizationStarted
protected long timeOptimizationStarted
currentTime
protected long currentTime
timeExceeded
protected boolean timeExceeded
noTimeout
private boolean noTimeout
useStatistics
private boolean useStatistics
tableLockThreshold
private int tableLockThreshold
joinStrategies
private org.apache.derby.iapi.sql.compile.JoinStrategy[] joinStrategies
requiredRowOrdering
protected org.apache.derby.iapi.sql.compile.RequiredRowOrdering requiredRowOrdering
foundABestPlan
private boolean foundABestPlan
sortCost
protected org.apache.derby.iapi.sql.compile.CostEstimate sortCost
currentRowOrdering
private org.apache.derby.iapi.sql.compile.RowOrdering currentRowOrdering
bestRowOrdering
private org.apache.derby.iapi.sql.compile.RowOrdering bestRowOrdering
conglomerate_OneRowResultSet
private boolean conglomerate_OneRowResultSet
optimizerTrace
protected boolean optimizerTrace
optimizerTraceHtml
protected boolean optimizerTraceHtml
maxMemoryPerTable
protected int maxMemoryPerTable
| Constructor Detail |
OptimizerImpl
protected OptimizerImpl(org.apache.derby.iapi.sql.compile.OptimizableList optimizableList, org.apache.derby.iapi.sql.compile.OptimizablePredicateList predicateList, org.apache.derby.iapi.sql.dictionary.DataDictionary dDictionary, boolean ruleBasedOptimization, boolean noTimeout, boolean useStatistics, int maxMemoryPerTable, org.apache.derby.iapi.sql.compile.JoinStrategy[] joinStrategies, int tableLockThreshold, org.apache.derby.iapi.sql.compile.RequiredRowOrdering requiredRowOrdering, int numTablesInQuery) throws org.apache.derby.iapi.error.StandardException
| Method Detail |
getMaxMemoryPerTable
public int getMaxMemoryPerTable()
- Specified by:
getMaxMemoryPerTablein interfaceorg.apache.derby.iapi.sql.compile.Optimizer
getNextPermutation
public boolean getNextPermutation()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Iterate through the permutations, returning false when the permutations
are exhausted.
NOTE - Implementers are responsible for hiding tree pruning of permutations
behind this method call.
- Specified by:
getNextPermutationin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
rewindJoinOrder
private void rewindJoinOrder()
throws org.apache.derby.iapi.error.StandardException
pushPredicates
void pushPredicates(org.apache.derby.iapi.sql.compile.Optimizable curTable, org.apache.derby.iapi.util.JBitSet outerTables) throws org.apache.derby.iapi.error.StandardException
getNextDecoratedPermutation
public boolean getNextDecoratedPermutation()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Iterate through the "decorated permutations", returning false when they
are exhausted.
NOTE - Implementers are responsible for hiding tree pruning of access
methods behind this method call.
- Specified by:
getNextDecoratedPermutationin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
rememberBestCost
private void rememberBestCost(org.apache.derby.iapi.sql.compile.CostEstimate currentCost, int planType) throws org.apache.derby.iapi.error.StandardException
- Is the cost of this join order lower than the best one we've
found so far? If so, remember it.
NOTE: If the user has specified a join order, it will be the
only join order the optimizer considers, so it is OK to use
costing to decide that it is the "best" join order.
costPermutation
public void costPermutation()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Cost the current permutation.
Caller is responsible for pushing all predicates which can be evaluated
prior to costing.
- Specified by:
costPermutationin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
costOptimizable
public void costOptimizable(org.apache.derby.iapi.sql.compile.Optimizable optimizable, org.apache.derby.iapi.sql.dictionary.TableDescriptor td, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd, org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList, org.apache.derby.iapi.sql.compile.CostEstimate outerCost) throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Cost the current Optimizable with the specified OPL.
Caller is responsible for pushing all predicates which can be evaluated
prior to costing.
- Specified by:
costOptimizablein interfaceorg.apache.derby.iapi.sql.compile.Optimizer
ruleBasedCostOptimizable
private void ruleBasedCostOptimizable(org.apache.derby.iapi.sql.compile.Optimizable optimizable, org.apache.derby.iapi.sql.dictionary.TableDescriptor td, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd, org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList, org.apache.derby.iapi.sql.compile.CostEstimate outerCost) throws org.apache.derby.iapi.error.StandardException
- This method decides whether the given conglomerate descriptor is
cheapest based on rules, rather than based on cost estimates.
The rules are:
Covering matching indexes are preferred above all
Non-covering matching indexes are next in order of preference
Covering non-matching indexes are next in order of preference
Heap scans are next in order of preference
Non-covering, non-matching indexes are last in order of
preference.
In the current language architecture, there will always be a
heap, so a non-covering, non-matching index scan will never be
chosen. However, the optimizer may see a non-covering, non-matching
index first, in which case it will choose it temporarily as the
best conglomerate seen so far.
NOTE: This method sets the cost in the optimizable, even though it
doesn't use the cost to determine which access path to choose. There
are two reasons for this: the cost might be needed to determine join
order, and the cost information is copied to the query plan.
costBasedCostOptimizable
private void costBasedCostOptimizable(org.apache.derby.iapi.sql.compile.Optimizable optimizable, org.apache.derby.iapi.sql.dictionary.TableDescriptor td, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd, org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList, org.apache.derby.iapi.sql.compile.CostEstimate outerCost) throws org.apache.derby.iapi.error.StandardException
- This method decides whether the given conglomerate descriptor is
cheapest based on cost, rather than based on rules. It compares
the cost of using the given ConglomerateDescriptor with the cost
of using the best ConglomerateDescriptor so far.
considerCost
public void considerCost(org.apache.derby.iapi.sql.compile.Optimizable optimizable, org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList, org.apache.derby.iapi.sql.compile.CostEstimate estimatedCost, org.apache.derby.iapi.sql.compile.CostEstimate outerCost) throws org.apache.derby.iapi.error.StandardException
- This is the version of costOptimizable for non-base-tables.
- Specified by:
considerCostin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
getDataDictionary
public org.apache.derby.iapi.sql.dictionary.DataDictionary getDataDictionary()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Return the DataDictionary that the Optimizer is using.
This is useful when an Optimizable needs to call optimize() on
a child ResultSetNode.
- Specified by:
getDataDictionaryin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
modifyAccessPaths
public void modifyAccessPaths()
throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Modify the access path for each Optimizable, as necessary. This includes
things like adding result sets to translate from index rows to base rows.
- Specified by:
modifyAccessPathsin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
newCostEstimate
public org.apache.derby.iapi.sql.compile.CostEstimate newCostEstimate()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Get a new CostEstimate object
- Specified by:
newCostEstimatein interfaceorg.apache.derby.iapi.sql.compile.Optimizer
getOptimizedCost
public org.apache.derby.iapi.sql.compile.CostEstimate getOptimizedCost()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Get the estimated cost of the optimized query
- Specified by:
getOptimizedCostin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
setOuterRows
public void setOuterRows(double outerRows)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Set the estimated number of outer rows - good for optimizing nested
optimizables like subqueries and join nodes.
- Specified by:
setOuterRowsin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
tableLockThreshold
public int tableLockThreshold()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Get the maximum number of estimated rows touched in a table before
we decide to open the table with table locking (as opposed to row
locking.
- Specified by:
tableLockThresholdin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
getNumberOfJoinStrategies
public int getNumberOfJoinStrategies()
- Get the number of join strategies supported by this optimizer.
- Specified by:
getNumberOfJoinStrategiesin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
getJoinStrategy
public org.apache.derby.iapi.sql.compile.JoinStrategy getJoinStrategy(int whichStrategy)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Gets a join strategy by number (zero-based).
- Specified by:
getJoinStrategyin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
getJoinStrategy
public org.apache.derby.iapi.sql.compile.JoinStrategy getJoinStrategy(java.lang.String whichStrategy)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Gets a join strategy by name. Returns null if not found.
The look-up is case-insensitive.
- Specified by:
getJoinStrategyin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
uniqueJoinWithOuterTable
public double uniqueJoinWithOuterTable(org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList) throws org.apache.derby.iapi.error.StandardException
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Tells whether any of the tables outer to the current one
has a uniqueness condition on the given predicate list,
and if so, how many times each unique key can be seen by
the current table.
- Specified by:
uniqueJoinWithOuterTablein interfaceorg.apache.derby.iapi.sql.compile.Optimizer
isPushable
private boolean isPushable(org.apache.derby.iapi.sql.compile.OptimizablePredicate pred)
estimateTotalCost
private org.apache.derby.iapi.sql.compile.CostEstimate estimateTotalCost(org.apache.derby.iapi.sql.compile.OptimizablePredicateList predList, org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor cd, org.apache.derby.iapi.sql.compile.CostEstimate outerCost, org.apache.derby.iapi.sql.compile.Optimizable optimizable) throws org.apache.derby.iapi.error.StandardException
- Estimate the total cost of doing a join with the given optimizable.
getLevel
public int getLevel()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Get the level of this optimizer.
- Specified by:
getLevelin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
getNewCostEstimate
public CostEstimateImpl getNewCostEstimate(double theCost, double theRowCount, double theSingleScanRowCount)
trace
public void trace(int traceFlag,
int intParam1,
int intParam2,
double doubleParam,
java.lang.Object objectParam1)
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - Optimizer trace.
- Specified by:
tracein interfaceorg.apache.derby.iapi.sql.compile.Optimizer
useStatistics
public boolean useStatistics()
- Description copied from interface:
org.apache.derby.iapi.sql.compile.Optimizer - If statistics should be considered by the optimizer while optimizing
a query. The user may disable the use of statistics by setting the
property derby.optimizer.useStatistics or by using the property
useStatistics in a query.
- Specified by:
useStatisticsin interfaceorg.apache.derby.iapi.sql.compile.Optimizer
|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> sql >> [ compile overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.derby.impl.sql.compile.OptimizerImpl