-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Blocker - P1
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Currently, the cost of the stand-alone `LIMIT` does not take into account the fact that:
- the input stage will be prematurely terminated on LIMIT values that are smaller than collection size
- limit values larger than the collection size should be disregarded
Enterprise test> db.foo.find({a: {$gte: 0}}).hint({$natural: 1}).limit(1).explain().queryPlanner.winningPlan;
{
isCached: false,
stage: 'LIMIT',
costEstimate: 0.6246551 <- Fixed value that is incorrect
estimatesMetadata: { ceSource: 'Metadata' },
limitAmount: 1,
inputStage: {
stage: 'COLLSCAN',
costEstimate: 4.3291855,
cardinalityEstimate: 10000,
numDocsEstimate: 10000,
estimatesMetadata: { ceSource: 'Histogram' },
filter: { a: { '$gte': 0 } },
direction: 'forward'
}
Enterprise test> db.foo.find({a: {$gte: 0}}).hint({$natural: 1}).limit(10000000000000000000000).explain().queryPlanner.winningPlan;
{
isCached: false,
stage: 'LIMIT',
costEstimate: 0.6246551,
cardinalityEstimate: 10000,
estimatesMetadata: { ceSource: 'Histogram' },
limitAmount: Long('9223372036854775807'),
inputStage: {
stage: 'COLLSCAN',
costEstimate: 4.3291855,
cardinalityEstimate: 10000,
numDocsEstimate: 10000,
estimatesMetadata: { ceSource: 'Histogram' },
filter: { a: { '$gte': 0 } },
direction: 'forward'
}
}
- is related to
-
SERVER-107606 CBR: Queries with $limit may pick inferior plan with residual predicate, correlation
-
- Needs Scheduling
-
- related to
-
SERVER-111534 Implement more advanced LIMIT costing
-
- Needs Scheduling
-