Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-36517

Allow allPaths indexes to provide DISTINCT_SCAN

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.4
    • 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.

            Assignee:
            bernard.gorman@mongodb.com Bernard Gorman
            Reporter:
            bernard.gorman@mongodb.com Bernard Gorman
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: