- 
    Type:Bug 
- 
    Resolution: Fixed
- 
    Priority:Major - P3 
- 
    Affects Version/s: None
- 
    Component/s: None
- 
    None
- 
        Query Optimization
- 
        Fully Compatible
- 
        ALL
- 
        
- 
        QO 2025-02-03
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
If the $limit is pushed into the $sort, the cardinality estimate of the SORT should reflect the limitAmount:
Enterprise test> db.foo.aggregate([{$sort: {b:1}}, {$limit: 100}]).explain().queryPlanner.winningPlan;
{
  isCached: false,
  stage: 'SORT',
  costEstimate: 7.0723816897747245,
  cardinalityEstimate: 1000, <- INCORRECT, MUST BE 100
  estimatesMetadata: { ceSource: 'Metadata' },
  sortPattern: { b: 1 },
  memLimit: 104857600,
  limitAmount: 100,
  type: 'simple',
  inputStage: {
    stage: 'COLLSCAN',
    costEstimate: 0.42847549999999995,
    cardinalityEstimate: 1000,
    numDocsEstimate: 1000,
    estimatesMetadata: { ceSource: 'Metadata' },
    direction: 'forward'
  }
}
- related to
- 
                    SERVER-99072 Support CE and costing of limit and skip stages -         
- Closed
 
-         
- 
                    SERVER-99907 Complete TODO listed in SERVER-99273 -         
- Closed
 
-