throws StandardException
{
/* CHOOSE BEST CONGLOMERATE HERE */
ConglomerateDescriptor conglomerateDescriptor = null;
ConglomerateDescriptor bestConglomerateDescriptor = null;
AccessPath bestAp = optimizable.getBestAccessPath();
int lockMode = optimizable.getCurrentAccessPath().getLockMode();
/*
** If the current conglomerate better than the best so far?
** The pecking order is:
** o covering index useful for predicates
** (if there are predicates)
** o index useful for predicates (if there are predicates)
** o covering index
** o table scan
*/
/*
** If there is more than one conglomerate descriptor
** choose any index that is potentially useful.
*/
if (predList != null &&
predList.useful(optimizable, cd))
{
/*
** Do not let a non-covering matching index scan supplant a
** covering matching index scan.
*/
boolean newCoveringIndex = optimizable.isCoveringIndex(cd);
if ( ( ! bestAp.getCoveringIndexScan()) ||
bestAp.getNonMatchingIndexScan() ||
newCoveringIndex )
{
bestAp.setCostEstimate(
estimateTotalCost(
predList,
cd,
outerCost,
optimizable
)
);
bestAp.setConglomerateDescriptor(cd);
bestAp.setNonMatchingIndexScan(false);
bestAp.setCoveringIndexScan(newCoveringIndex);
bestAp.setLockMode(optimizable.getCurrentAccessPath().getLockMode());
optimizable.rememberJoinStrategyAsBest(bestAp);
}
return;
}
/* Remember the "last" covering index.
* NOTE - Since we don't have costing, we just go for the
* last one since that's as good as any
*/
if (optimizable.isCoveringIndex(cd))
{
bestAp.setCostEstimate(
estimateTotalCost(predList,
cd,
outerCost,
optimizable)
);
bestAp.setConglomerateDescriptor(cd);
bestAp.setNonMatchingIndexScan(true);
bestAp.setCoveringIndexScan(true);
bestAp.setLockMode(optimizable.getCurrentAccessPath().getLockMode());
optimizable.rememberJoinStrategyAsBest(bestAp);
return;
}
/*
** If this is the heap, and the best conglomerate so far is a
** non-covering, non-matching index scan, pick the heap.
*/
if ( ( ! bestAp.getCoveringIndexScan()) &&
bestAp.getNonMatchingIndexScan() &&
( ! cd.isIndex() )
)
{
bestAp.setCostEstimate(
estimateTotalCost(predList,
cd,
outerCost,
optimizable)
);
bestAp.setConglomerateDescriptor(cd);
bestAp.setLockMode(optimizable.getCurrentAccessPath().getLockMode());
optimizable.rememberJoinStrategyAsBest(bestAp);
/*
** No need to set non-matching index scan and covering
** index scan, as these are already correct.
*/
return;
}
/*
** If all else fails, and no conglomerate has been picked yet,
** pick this one.
*/
bestConglomerateDescriptor = bestAp.getConglomerateDescriptor();
if (bestConglomerateDescriptor == null)
{
bestAp.setCostEstimate(
estimateTotalCost(predList,
cd,
outerCost,
optimizable)
);
bestAp.setConglomerateDescriptor(cd);
/*
** We have determined above that this index is neither covering
** nor matching.
*/
bestAp.setCoveringIndexScan(false);
bestAp.setNonMatchingIndexScan(cd.isIndex());
bestAp.setLockMode(optimizable.getCurrentAccessPath().getLockMode());
optimizable.rememberJoinStrategyAsBest(bestAp);
}
return;