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

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

      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.

            Assignee:
            aaron Aaron Staple
            Reporter:
            srstrong Steve Strong
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: