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

Cost of collection and index scan should depend on input size

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • Fully Compatible
    • ALL
    • QO 2024-12-09

      The cost  of a COLLSCAN should not depend on the selectivity of the predicate. The entire collection needs to be read end-to-end, at a cost proportional to the size of the collection.

       

      coll = db.foo;
      coll.drop();
      for (let i = 1000; i < 1100; i++) {
           coll.insertMany([{a: 1, b: i, c: 5, x: [i, i+1, i+3]},
                            {a: 1, b: i, c: 6, x: [i, i+1, i+5]},
                            {a: 1, b: i, c: 7, x: [i, i+2, i+7]}]);
       }
      
      db.foo.find({}).explain();
      ...
            costEstimate: 0.3112368,
            estimatesMetadata: { ceSource: 'Metadata' },
      ...
      
      db.foo.find({zzz:1}).explain();
      ...
            costEstimate: 0.02003121809848288,
            estimatesMetadata: { ceSource: 'Heuristics' },
      ...
       

            Assignee:
            timour.katchaounov@mongodb.com Timour Katchaounov
            Reporter:
            philip.stoev@mongodb.com Philip Stoev
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: