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

Using "OR" in a query with ordering results in extremely long (possibly exponential) search times

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Environment:
      Ubuntu and OSX 10.8
    • Operating System:
      ALL

      Description

      Issuing a query such as:

      db.events.find({$query : {$or : [{foo : {$in : []}}, {bar : {$in : []}}]}, $orderby : {_id : 1}})

      on a reasonably large table (my events table has 1.2million entries, each using around 6.5k), then the query takes a long time to return (approx 1 minute).

      Reducing the number of OR clauses to one, and it returns immediately. Extend the number of OR clauses to 3, and it never returns (at least, not that I've waited for!)

      Remove the orderby and they all return instantly.

      Note that the documents in my events table has neither a foo or a bar field, so I suspect this is easy to reproduce on any reasonably sized table.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: