-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 8.2.0, 8.0.16, 7.0.31, 8.3.0
-
Component/s: None
-
Query Optimization
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
When a CWI index is used with a $ne: null predicate on a non-wildcard indexed field alongside a wildcard-field predicate, the query planner now inserts an unnecessary FETCH stage. This is a regression introduced by SERVER-95374.
A regular non-sparse compound index, a non-wildcard sparse index, and a non-wildcard sparse compound index all produce covered plans for $ne: null.
CWI matched this behaviour before SERVER-95374.
Example
db.demo.drop();
db.demo.createIndex({ "w.$**": 1, unit: 1 });
db.demo.insertMany([
{ w: { x: "A" }, unit: 1 },
{ w: { x: "A" }, unit: 2 },
{ w: { x: "B" }, unit: 3 },
{ w: { x: "B" }, unit: 4 },
]);
Before SERVER-95374, this query was covered (totalDocsExamined = 0, PROJECTION_COVERED):
db.demo.aggregate([
{ $match: { "w.x": "A", unit: { $ne: null } } },
{ $project: { _id: 0, unit: 1 } },
]);
After SERVER-95374 it produces PROJECTION_SIMPLE with a FETCH stage and totalDocsExamined = 4.
Fix
traverseAndPropagateANDRelatedPredicates strips index assignments from all $not nodes unconditionally, rather than applying the same $ne: null exception that nodeIsSupportedBySparseIndex already carves out for sparse indexes. Smarter stripping logic - analogous to that can restore the pre-regression behaviour.
- is caused by
-
SERVER-95374 Compound wildcard indexes can incorrectly push down predicates during union or planning
-
- Closed
-
- related to
-
SERVER-128261 Compound Wildcard Index can avoid FETCH for $ne: <scalar> on indexed non-wildcard field
-
- Needs Scheduling
-