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;
- is related to
-
SERVER-109891 samplingCE: cardinalityEstimate is zero for $type, $ne, $nin, $regex
-
- Closed
-
- related to
-
SERVER-109336 samplingCE: cardinalityEstimate is incorrect for $ne
-
- Closed
-