samplingCE: numKeysEstimate is incorrect with missing/null values, $ne, descending index

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Blocker - P1
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      If there is a null or a missing value either in the data or in the predicate, and the index is descending, the numKeysEstimate value is zero . This is different from SERVER-109336 where the cardinalityEstimate is incorrect but the numKeysEstimate is correct.

      To reproduce:

      db.foo.drop();
      db.foo.insertMany([
        {a: null}, // Or missing
        {a: 1}
      ]);
      db.foo.createIndex({a: -1});
      
      // Returns 1 row
      db.foo.find({a:{$ne: 1}});
      // Returns 0
      db.foo.find({a:{$ne: 1}}).explain().queryPlanner.winningPlan.inputStage.numKeysEstimate;
      
      // Returns 1 row
      db.foo.find({a:{$ne: null}});
      // Returns 0
      db.foo.find({a:{$ne: null}}).explain().queryPlanner.winningPlan.inputStage.numKeysEstimate; 
      

            Assignee:
            Unassigned
            Reporter:
            Philip Stoev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: