[SERVER-7327] Using "OR" in a query with ordering results in extremely long (possibly exponential) search times Created: 11/Oct/12  Updated: 15/Feb/13  Resolved: 11/Oct/12

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.2.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Steve Strong Assignee: Aaron Staple
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu and OSX 10.8


Issue Links:
Duplicate
duplicates SERVER-1205 $or sort does not use index ranges ex... Closed
Operating System: ALL
Participants:

 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.



 Comments   
Comment by Aaron Staple [ 11/Oct/12 ]

This is SERVER-1205

Generated at Thu Feb 08 03:14:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.