[SERVER-393] $exists queries should use index Created: 28/Oct/09 Updated: 12/Jul/16 Resolved: 06/Apr/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | 1.9.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Mathias Stearn | Assignee: | Aaron Staple |
| Resolution: | Done | Votes: | 19 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Participants: | |||||||||||||||||
| Comments |
| Comment by auto [ 05/Apr/11 ] |
|
Author: {u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}Message: |
| Comment by auto [ 05/Apr/11 ] |
|
Author: {u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}Message: |
| Comment by auto [ 05/Apr/11 ] |
|
Author: {u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}Message: |
| Comment by Scott Hernandez (Inactive) [ 03/Jun/10 ] |
|
(If you, like me, are searching for the issue about why $exists fails in the cases below, this is the issue to watch. Taken from a duplicate issue.) > db.people.save( { fname: "BOB", lname: "SMITH" }) ) { "_id" : ObjectId("4c06e2eb4138a24d33ee0fdc"), "fname" : "BOB", "lname" : "SMITH" }> db.people.save( { fname: "BOB", lname: "SMITH", mname: "ROBERT", suffix: "JR" }) ); }) - It sure seems like it is using the index and not finding the correct doc (as shown below). Also, using null for the missing field value returns the doc even thought that is incorrect (since the index stores a null for that index value). > db.people.find( { lname: "SMITH", mname: null }) { "_id" : ObjectId("4c06e2eb4138a24d33ee0fdc"), "fname" : "BOB", "lname" : "SMITH" } |
| Comment by Mathias Stearn [ 07/Dec/09 ] |
|
Need to meet to discuss desired sort order. |
| Comment by Dwight Merriman [ 18/Nov/09 ] |
|
also: > db.order.find().sort( {x:1}) { "_id" : ObjectId("4b045b0beda5232d46e5db6b") }{ "_id" : ObjectId("4b045b40eda5232d46e5db6e"), "x" : { $minKey : 1 }} { "_id" : ObjectId("4b045b15eda5232d46e5db6c"), "x" : null } { "_id" : ObjectId("4b045b1beda5232d46e5db6d"), "x" : 1 }{ "_id" : ObjectId("4b045b42eda5232d46e5db6f"), "x" : { $maxKey : 1 } } ) ) } { "_id" : ObjectId("4b045b0beda5232d46e5db6b") } { "_id" : ObjectId("4b045b15eda5232d46e5db6c"), "x" : null } { "_id" : ObjectId("4b045b1beda5232d46e5db6d"), "x" : 1 }{ "_id" : ObjectId("4b045b42eda5232d46e5db6f"), "x" : { $maxKey : 1 }} in the above, i think the order is right for the indexed case, which means this part of the problem can be fixed without an index change. |
| Comment by Mathias Stearn [ 28/Oct/09 ] |
|
Pushing to 1.3.0 because fixing this will require adjusting sort order for null. |