|
Currently, allPaths indexes cannot provide a DISTINCT_SCAN because the 'distinct' field does not appear in the index's $** keyPattern:
IndexCatalog::IndexIterator ii = collection->getIndexCatalog()->getIndexIterator(opCtx, false);
|
while (ii.more()) {
|
const IndexDescriptor* desc = ii.next();
|
IndexCatalogEntry* ice = ii.catalogEntry(desc);
|
if (desc->keyPattern().hasField(parsedDistinct->getKey())) {
|
plannerParams.indices.push_back(IndexEntry(desc->keyPattern(),
|
desc->getAccessMethodName(),
|
desc->isMultikey(opCtx),
|
ice->getMultikeyPaths(opCtx),
|
desc->isSparse(),
|
desc->unique(),
|
desc->indexName(),
|
ice->getFilterExpression(),
|
desc->infoObj(),
|
ice->getCollator()));
|
}
|
}
|
|
const ExtensionsCallbackReal extensionsCallback(opCtx, &collection->ns());
|
|
// If there are no suitable indices for the distinct hack bail out now into regular planning
|
// with no projection.
|
if (plannerParams.indices.empty()) {
|
return getExecutor(opCtx, collection, parsedDistinct->releaseQuery(), yieldPolicy);
|
}
|
We should allow getExecutorDistinct to take advantage of allPaths when determining which indexes are relevant. This work will also require DistinctScanParams and DistinctScan to take their keyPattern and multikeyPaths information from the generated allPaths IndexEntry rather than from the IndexDescriptor.
|