Search in sources :

Example 1 with RequiredRowOrdering

use of org.apache.derby.iapi.sql.compile.RequiredRowOrdering in project derby by apache.

the class TableOperatorNode method optimizeSource.

/**
 * Optimize a source result set to this table operator.
 *
 * @exception StandardException		Thrown on error
 */
protected ResultSetNode optimizeSource(Optimizer optimizer, ResultSetNode sourceResultSet, PredicateList predList, CostEstimate outerCost) throws StandardException {
    ResultSetNode retval;
    if (sourceResultSet instanceof FromTable) {
        FromList optList = new FromList(getOptimizerFactory().doJoinOrderOptimization(), (FromTable) sourceResultSet, getContextManager());
        /* If there is no predicate list, create an empty one */
        if (predList == null)
            predList = new PredicateList(getContextManager());
        // recursively create a new optimizer
        LanguageConnectionContext lcc = getLanguageConnectionContext();
        OptimizerFactory optimizerFactory = lcc.getOptimizerFactory();
        optimizer = optimizerFactory.getOptimizer(optList, predList, getDataDictionary(), (RequiredRowOrdering) null, getCompilerContext().getNumTables(), null, lcc);
        optimizer.prepForNextRound();
        if (sourceResultSet == leftResultSet) {
            leftOptimizer = optimizer;
        } else if (sourceResultSet == rightResultSet) {
            rightOptimizer = optimizer;
        } else {
            if (SanityManager.DEBUG)
                SanityManager.THROWASSERT("Result set being optimized is neither left nor right");
        }
        /*
			** Set the estimated number of outer rows from the outer part of
			** the plan.
			*/
        optimizer.setOuterRows(outerCost.rowCount());
        /* Optimize the underlying result set */
        while (optimizer.getNextPermutation()) {
            while (optimizer.getNextDecoratedPermutation()) {
                optimizer.costPermutation();
            }
        }
        retval = sourceResultSet;
        // dispose of the recursively created optimizer
        if (optimizerTracingIsOn()) {
            getOptimizerTracer().traceEndQueryBlock();
        }
    } else {
        retval = sourceResultSet.optimize(getDataDictionary(), predList, outerCost.rowCount());
    }
    return retval;
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) RequiredRowOrdering(org.apache.derby.iapi.sql.compile.RequiredRowOrdering) OptimizerFactory(org.apache.derby.iapi.sql.compile.OptimizerFactory)

Aggregations

OptimizerFactory (org.apache.derby.iapi.sql.compile.OptimizerFactory)1 RequiredRowOrdering (org.apache.derby.iapi.sql.compile.RequiredRowOrdering)1 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)1