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

Count is even slower than find(...)->sort(...)->limit(...)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.8.2
    • Component/s: Performance, Querying
    • Environment:
      Mac OS X 10.6.8 2.16 GHz
      Intel Core 2 Duo
      2 GB 667 MHz DDR2 SDRAM
    • ALL

      I'm using a dummy collection of 18M rows in the following format:

      { _id: __unique_of_course__, name: __also_unique__, dummyID: __not_unique__ }

      There's an additional index on dummyID:
      db.dummy.ensureIndex(

      {dummyID: 1}

      );

      Now, when I query it ...
      db.dummy.count(

      {dummyID: __not_unique__}

      );

      This will take several seconds ....

      Now, when I query the following ...
      db.dummy.find(

      {dummyID: __not_unique__}

      ).sort(

      {dummyID: -1}

      ).limit(10);

      This takes just one ms or so ...

      Is this some bug, or did I just forgot something?

      It'ld make sense if sorting a 18M result-set took more time than counting it ...

      (note: it may be faster when testing it on a real server, I'm testing it on my MacBook right now. Look at the relative difference between the benchmarks).

            Assignee:
            Unassigned Unassigned
            Reporter:
            timvanelsloo Tim van Elsloo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: