Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-100647

Pushdown stand-alone LIMIT into streaming operators while estimating CE

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization

      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'
        }
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            philip.stoev@mongodb.com Philip Stoev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: