-
Type: Task
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
Histogram CE produces an incorrect estimate for 'int' values because it incorrectly determines that the type of the value is double and returns the counter for double instead of that for integer. The code in question (checked via GDB) is in
estimateCardinalityRangeViaTypeCounts()
Test case:
const collName = 'wrong_int_count'; const coll = db[collName]; coll.drop(); coll.insertMany(Array.from({length: 9999}, (_, i) => { const doc = {mixed: 3.14}; return doc; })); coll.insertMany(Array.from({length: 427}, (_, i) => { const doc = {mixed: i}; return doc; })); coll.createIndexes([{mixed: 1}]); coll.runCommand({analyze: collName, key: "mixed", numberBuckets: 10}); db.adminCommand({setParameter: 1, planRankerMode: "histogramCE"}); coll.find({mixed: {$type: 'int'}}).count(); coll.find({mixed: {$type: 'double'}}).count(); coll.find({mixed: {$type: 'int'}}).explain().queryPlanner.winningPlan; coll.find({mixed: {$type: 'double'}}).explain().queryPlanner.winningPlan;