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

sort() after geoNear/geoWithin find/aggregate doesn't use the index

    • ALL
    • Hide

      1. Take a big collection (more than 1,000,000 documents) with Points (geospatial data). Be sure a 2D or 2DSphere index is applied to the Point field.
      2. Run a find() or aggregate() using geoNear or geoWithin, after which a sort() should be applied on an indexed field, after which a limit() should be set.
      3. Run explain on the query above and you'll see the index is not used, as scanAndOrder=true and the number of scanned objects is very high.

      Show
      1. Take a big collection (more than 1,000,000 documents) with Points (geospatial data). Be sure a 2D or 2DSphere index is applied to the Point field. 2. Run a find() or aggregate() using geoNear or geoWithin, after which a sort() should be applied on an indexed field, after which a limit() should be set. 3. Run explain on the query above and you'll see the index is not used, as scanAndOrder=true and the number of scanned objects is very high.

      Sorting a result by a single field on a find() or aggregate() result that uses geoNear or geoWithin and limiting the result (e.g. to 1,000 documents) yields a very slow response time. Running explain shows scanAndOrder=true and a very high number of scanned documents.

      If you remove the geoNear/geoWithin and get the whole collection, the sort is very fast, and explain shows scanAndOrder=false and a number of low number of scanned documents, which is equal to the limit specified.

            Assignee:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Reporter:
            aplimovil Abraham Lopez
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: