-
Type: Improvement
-
Resolution: Unresolved
-
Priority: 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));