Search in sources :

Example 6 with Optimizable

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));
    }
}
Also used : JBitSet(org.apache.derby.iapi.util.JBitSet) Optimizable(org.apache.derby.iapi.sql.compile.Optimizable)

Example 7 with Optimizable

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;
}
Also used : Optimizable(org.apache.derby.iapi.sql.compile.Optimizable)

Example 8 with Optimizable

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;
}
Also used : Optimizable(org.apache.derby.iapi.sql.compile.Optimizable)

Example 9 with Optimizable

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);
    }
}
Also used : AccessPath(org.apache.derby.iapi.sql.compile.AccessPath) Optimizable(org.apache.derby.iapi.sql.compile.Optimizable)

Example 10 with Optimizable

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;
}
Also used : CostEstimate(org.apache.derby.iapi.sql.compile.CostEstimate) Optimizable(org.apache.derby.iapi.sql.compile.Optimizable)

Aggregations

Optimizable (org.apache.derby.iapi.sql.compile.Optimizable)23 CostEstimate (org.apache.derby.iapi.sql.compile.CostEstimate)9 AccessPath (org.apache.derby.iapi.sql.compile.AccessPath)3 OptimizerPlan (org.apache.derby.iapi.sql.compile.OptimizerPlan)2 JBitSet (org.apache.derby.iapi.util.JBitSet)2 Element (org.w3c.dom.Element)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 JoinStrategy (org.apache.derby.iapi.sql.compile.JoinStrategy)1 OptimizablePredicate (org.apache.derby.iapi.sql.compile.OptimizablePredicate)1 OptimizablePredicateList (org.apache.derby.iapi.sql.compile.OptimizablePredicateList)1 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)1 UniqueTupleDescriptor (org.apache.derby.iapi.sql.dictionary.UniqueTupleDescriptor)1 StandardException (org.apache.derby.shared.common.error.StandardException)1