...
BugZero found this defect 17 days ago.
If a more complex predicate is completely evaluated by e.g. AND_SORTED and there is no residual predicate for FETCH to evaluate, the cardinality estimate should be equal to the estimate of the input stage. winningPlan: { isCached: false, stage: 'FETCH', cardinalityEstimate: 0.0023713737056616554, <<<< INCORRECT costEstimate: 0.04108509091715634, estimatesMetadata: { ceSource: 'Histogram' }, filter: { '$and': [ { a: { '$eq': 1 } }, { b: { '$eq': 1 } } ] }, inputStage: { stage: 'AND_SORTED', cardinalityEstimate: 0.0316227766016838, costEstimate: 0.0291674, estimatesMetadata: { ceSource: 'Histogram' },
coll = db.foo; coll.drop();for (let i = 0; i < 1000; i++) { coll.insertMany([{a: i, b: i, c: i}]); } coll.createIndex({a: 1}); coll.createIndex({b:1}); db.adminCommand({setParameter: 1, planRankerMode: "multiPlanning"}); db.runCommand({analyze: "foo", key: "a"}); db.runCommand({analyze: "foo", key: "b"});db.adminCommand({setParameter: 1, planRankerMode: "multiPlanning"}); db.foo.aggregate([{$match:{a: 1,b:1}}]).explain().queryPlanner; db.adminCommand({setParameter: 1, planRankerMode: "automaticCE"}); db.foo.aggregate([{$match:{a: 1,b:1}}]).explain().queryPlanner; db.adminCommand({setParameter: 1, planRankerMode: "histogramCE"}); db.foo.aggregate([{$match:{a: 1,b:1}}]).explain().queryPlanner; db.adminCommand({setParameter: 1, planRankerMode: "heuristicCE"}); db.foo.aggregate([{$match:{a: 1,b:1}}]).explain().queryPlanner;