-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
QO 2025-02-03
Currently:
- if there is no index, $type is estimated via heuristics, and the estimate is off
- if there is an index, $type is reported as ceSource: Mixed, and is also inaccurate.
Enterprise test> db.foo.find({a: {$type: 'int'}}).explain().queryPlanner.winningPlan;
...
cardinalityEstimate: 16.5, <- incorrect
numKeysEstimate: 50, <- correct
From what I can see, there is a valid indexBound:
indexBounds: { a: [ '[nan.0, inf.0]' ] }
So a correct estimation should be possible.
To reproduce:
db.foo.drop(); let docs = []; for (let i = 0; i < 50; i++) { docs.push({a: i}); } db.foo.createIndex({a: 1}); db.foo.insertMany(docs); db.foo.runCommand({analyze: "foo", key: "a"}); db.adminCommand({setParameter: 1, planRankerMode: "histogramCE"}); db.foo.find({a: {$type: 'int'}}).explain().queryPlanner.winningPlan;
- is fixed by
-
SERVER-99029 Histogram CE for AND/OR trees of all sargable ME nodes
- Closed