use of org.apache.derby.iapi.sql.compile.Optimizable in project derby by apache.
the class OptimizerImpl method modifyAccessPaths.
/**
* @see Optimizer#modifyAccessPaths
*
* @exception StandardException Thrown on error
*/
public void modifyAccessPaths() throws StandardException {
if (tracingIsOn()) {
tracer().traceModifyingAccessPaths(hashCode());
}
if (!foundABestPlan) {
if (tracingIsOn()) {
tracer().traceNoBestPlan();
}
throw StandardException.newException(SQLState.LANG_NO_BEST_PLAN_FOUND);
}
/* Change the join order of the list of optimizables */
optimizableList.reOrder(bestJoinOrder);
/* Form a bit map of the tables as they are put into the join order */
JBitSet outerTables = new JBitSet(numOptimizables);
/* Modify the access path of each table, as necessary */
for (int ictr = 0; ictr < numOptimizables; ictr++) {
Optimizable optimizable = optimizableList.getOptimizable(ictr);
/* Current table is treated as an outer table */
outerTables.or(optimizable.getReferencedTableMap());
/*
** Push any appropriate predicates from this optimizer's list
** to the optimizable, as appropriate.
*/
pushPredicates(optimizable, outerTables);
optimizableList.setOptimizable(ictr, optimizable.modifyAccessPath(outerTables));
}
}
use of org.apache.derby.iapi.sql.compile.Optimizable in project derby by apache.
the class OptimizerImpl method uniqueJoinWithOuterTable.
/**
* @see Optimizer#uniqueJoinWithOuterTable
*
* @exception StandardException Thrown on error
*/
public double uniqueJoinWithOuterTable(OptimizablePredicateList predList) throws StandardException {
double retval = -1.0;
double numUniqueKeys = 1.0;
double currentRows = currentCost.rowCount();
if (predList != null) {
for (int i = joinPosition - 1; i >= 0; i--) {
Optimizable opt = optimizableList.getOptimizable(proposedJoinOrder[i]);
double uniqueKeysThisOptimizable = opt.uniqueJoin(predList);
if (uniqueKeysThisOptimizable > 0.0)
numUniqueKeys *= opt.uniqueJoin(predList);
}
}
if (numUniqueKeys != 1.0) {
retval = numUniqueKeys / currentRows;
}
return retval;
}
use of org.apache.derby.iapi.sql.compile.Optimizable in project derby by apache.
the class RowOrderingImpl method toString.
@Override
public String toString() {
String retval = null;
if (SanityManager.DEBUG) {
int i;
retval = "Unordered optimizables: ";
for (i = 0; i < unorderedOptimizables.size(); i++) {
Optimizable opt = unorderedOptimizables.get(i);
if (opt.getBaseTableName() != null) {
retval += opt.getBaseTableName();
} else {
retval += unorderedOptimizables.get(i).toString();
}
retval += " ";
}
retval += "\n";
retval += "\nAlways ordered optimizables: ";
for (i = 0; i < alwaysOrderedOptimizables.size(); i++) {
Optimizable opt = alwaysOrderedOptimizables.get(i);
if (opt.getBaseTableName() != null) {
retval += opt.getBaseTableName();
} else {
retval += alwaysOrderedOptimizables.get(i).toString();
}
retval += " ";
}
retval += "\n";
for (i = 0; i < ordering.size(); i++) {
retval += " ColumnOrdering " + i + ": " + ordering.get(i);
}
}
return retval;
}
use of org.apache.derby.iapi.sql.compile.Optimizable in project derby by apache.
the class FromTable method rememberAsBest.
/**
* @see Optimizable#rememberAsBest
*/
public void rememberAsBest(int planType, Optimizer optimizer) throws StandardException {
AccessPath bestPath = null;
switch(planType) {
case Optimizer.NORMAL_PLAN:
bestPath = getBestAccessPath();
break;
case Optimizer.SORT_AVOIDANCE_PLAN:
bestPath = getBestSortAvoidancePath();
break;
default:
if (SanityManager.DEBUG) {
SanityManager.THROWASSERT("Invalid plan type " + planType);
}
}
getTrulyTheBestAccessPath().copy(bestPath);
// just end up duplicating the work.
if (!(this instanceof ProjectRestrictNode))
updateBestPlanMap(ADD_PLAN, optimizer);
else {
ProjectRestrictNode prn = (ProjectRestrictNode) this;
if (!(prn.getChildResult() instanceof Optimizable))
updateBestPlanMap(ADD_PLAN, optimizer);
}
if (isBaseTable()) {
DataDictionary dd = getDataDictionary();
TableDescriptor td = getTableDescriptor();
getTrulyTheBestAccessPath().initializeAccessPathName(dd, td);
}
setCostEstimateCost(bestPath.getCostEstimate());
if (optimizerTracingIsOn()) {
getOptimizerTracer().traceRememberingBestAccessPath(bestPath, tableNumber, planType);
}
}
use of org.apache.derby.iapi.sql.compile.Optimizable in project derby by apache.
the class GroupByNode method optimizeIt.
/*
* Optimizable interface
*/
/**
* @see Optimizable#optimizeIt
*
* @exception StandardException Thrown on error
*/
@Override
public CostEstimate optimizeIt(Optimizer optimizer, OptimizablePredicateList predList, CostEstimate outerCost, RowOrdering rowOrdering) throws StandardException {
// RESOLVE: NEED TO FACTOR IN THE COST OF GROUPING (SORTING) HERE
((Optimizable) childResult).optimizeIt(optimizer, predList, outerCost, rowOrdering);
CostEstimate retval = super.optimizeIt(optimizer, predList, outerCost, rowOrdering);
return retval;
}
Aggregations