[SERVER-36517] Allow allPaths indexes to provide DISTINCT_SCAN Created: 08/Aug/18  Updated: 29/Oct/23  Resolved: 11/Oct/18

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying
Affects Version/s: None
Fix Version/s: 4.1.4

Type: Task Priority: Major - P3
Reporter: Bernard Gorman Assignee: Bernard Gorman
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-9507 Optimize $sort+$group+$first pipeline... Closed
is depended on by SERVER-36198 Enable $** index builds by default in... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2018-09-24, Query 2018-10-08, Query 2018-10-22
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 11/Oct/18 ]

Author:

{'name': 'Bernard Gorman', 'email': 'bernard.gorman@gmail.com', 'username': 'gormanb'}

Message: SERVER-36517 Allow wildcard indexes to provide DISTINCT_SCAN
Branch: master
https://github.com/mongodb/mongo/commit/8dab2485c1badc2fd09b84667b4dcfc8b53fef63

Generated at Thu Feb 08 04:43:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.