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

Support bounding clustered collection scans for $regex op

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Execution

      We currently support bounding clustered collection scans when there's a comparison match expression on the cluster key: https://github.com/10gen/mongo/blob/fd275f66b712e0af181b53575efbe8a87f214a5e/src/mongo/db/query/planner_access.cpp#L267-L272

      It should be easy to support the $regex operator when the query and collection collators match using the existing IndexBoundsBuilder. Something like this:

          IndexEntry ie{BSON("_id"_sd << 1),
                        IndexType::INDEX_BTREE,
                        IndexDescriptor::IndexVersion::kV2,
                        false,
                        {},
                        {},
                        false,
                        true,
                        CoreIndexInfo::Identifier("clustered"),
                        nullptr,
                        {},
                        params.clusteredCollectionCollator,
                        nullptr};
          OrderedIntervalList oil;
          IndexBoundsBuilder::BoundsTightness bt;
          IndexBoundsBuilder::translateRegex(regexExpr, BSON("_id"_sd << 1).firstElement(), ie, &oil, &bt);
      
          const auto& interval = oil.intervals.front(); // second interval is for regex objects, not possible in _id
      
          setMinRecord(collScan, record_id_helpers::keyForElem(interval.start, nullptr));
          setMaxRecord(collScan, record_id_helpers::keyForElem(interval.end, nullptr));
      

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            daniel.gomezferro@mongodb.com Daniel Gomez Ferro
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: