-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Index Maintenance, Querying
-
None
-
Fully Compatible
-
Query 2018-09-24, Query 2018-10-08, Query 2018-10-22
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.
- depends on
-
SERVER-9507 Optimize $sort+$group+$first pipeline to avoid full index scan
- Closed
- is depended on by
-
SERVER-36198 Enable $** index builds by default in non-test configurations
- Closed