-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
ALL
-
QO 2025-02-03
-
None
-
None
-
None
-
None
-
None
-
None
-
None
If the dataset contains two different number types and the predicate contains a string literal, negation is estimated incorrectly:
db.foo.drop();
let number_docs = [];
number_docs.push({a: 1});
number_docs.push({a: 2.5});
db.foo.insert(number_docs);
db.foo.createIndex({a:1});
db.foo.runCommand({analyze: "foo", key: "a"});
db.foo.find({ "a" : { "$ne" : "ABC" } }).explain().queryPlanner.winningPlan.cardinalityEstimate; <- returns 1 incorrectly
db.foo.find({ "a" : { "$ne" : "ABC" } }).count(); <- returns 2 correctly
In other words, only one of the two datatypes present in the dataset is taken into account when estimating the predicate.
This is not a off-by-one issue, as if the table had 20K values, the estimate would be incorrect by 10K.