Allow allPaths indexes to provide DISTINCT_SCAN

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Fixed
    • Priority: 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
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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
            Reporter:
            Bernard Gorman
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: