[SERVER-5338] Strange results with identical but differently structured queries Created: 19/Mar/12 Updated: 07/Mar/14 Resolved: 26/Feb/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 2.0.3 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Nic Cottrell (Personal) | Assignee: | Aaron Staple |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Description |
|
I am tracking some slow queries and found some odd behavior. This query (generated by Morphia) scans 20k objects and correctly returns 22 objects: db.Example.find({ $and: [ { lc: "eng" }, { $or: [ { group: "cn" }, { group: "all" }] }, { "indices.textLc": { $in: [ "media strengthening", "strengthening", "media" ] }}, { wordCount: { $gte: 1 , $lte: 2 }} ] }).explain(); But it has this in the indexBounds: "wordCount" : [ [1,1.7976931348623157e+308]], This other query has the same limits and gives the same 22 objects, but only scans 4k objects: db.Example.find( {lc: "eng" , $or: [ { group: "cn" }, { group: "all" }], "indices.textLc": { $in: [ "media strengthening", "strengthening", "media" ] }, wordCount: { $gte: 1 , $lte: 2 }}).explain(); This explain gives the same unbound max wordCount, but is obviously much faster. Is this something that can be fixed in the server or do I need to restructure all my queries? |
| Comments |
| Comment by Aaron Staple [ 26/Feb/13 ] |
|
Hi Nic - $or behaves differently with indexing when nested within a $and. This was part of the specced behavior of |