Compound Wildcard Index $ne: null on indexed non-wildcard field no longer produces covered plan

XMLWordPrintableJSON

    • 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.

            Assignee:
            Unassigned
            Reporter:
            Vesko Karaganev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: