[SERVER-1896] limit() clause is not being pushed down to the shard for evaluation, causing more documents to be returned than are needed Created: 05/Oct/10 Updated: 12/Jul/16 Resolved: 10/Nov/10 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 1.7.0 |
| Fix Version/s: | 1.7.3 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alvin Richards (Inactive) | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
1.7.2-pre- |
||
| Operating System: | ALL |
| Participants: |
| Description |
|
Problem: For example, given the shard key "x" has values 0-100 and the split is at 50. Given the query db.test20101005.find( {x : { $lt : 60}} ).sort( { x:-1}).limit(1).explain() produces > db.test20101005.find( {x : { $lt : 60}} ).sort( { x:-1} ).limit(1).explain() } } The value of "n" indicates that shard0000 returns 50 documents, and shard0001 returns 10 before the final sort & limit is applied by the mongos. Reproduce: ); } ) ) { "ok" : 1 }> db.runCommand( { shardcollection : "test.test20101005", key : { x : 1 }} ) { "collectionsharded" : "test.test20101005", "ok" : 1 }> db.runCommand( { split : "test.test20101005", middle : { x : 50 }} ); { "ok" : 1 }> db.runCommand( { moveChunk: "test.test20101005", find : { x : 51}, to : "shard0001" }) { "millis" : 2413, "ok" : 1 }> use test ).limit(1).explain() } } Solution: Business Case: |
| Comments |
| Comment by Eliot Horowitz (Inactive) [ 10/Nov/10 ] |
|
Note: as far as I can tell this is just an explain() issue, not a normal query issue. |
| Comment by auto [ 10/Nov/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: fix limit on explain |
| Comment by Yuri Buyanov [ 19/Oct/10 ] |
|
As I can see in our test environment, this also seem to affect 1.6.3 (debian mongodb-stable 20101018). > db.related.find( {"user.old_pk" : 902}).limit(1).explain() , { "$minElement" : 1 } ] |
| Comment by Alvin Richards (Inactive) [ 06/Oct/10 ] |
|
Added jstest/sharding/limit_push.js. Execution is commented out, so you will need to uncomment in order to get the test to fail. Per the update above, on a non-sharded system, n=1. It appears at least from the explain output that each shard is return n > 1. |
| Comment by auto [ 06/Oct/10 ] |
|
Author: {'login': 'alvin10gen', 'name': 'Alvin Richards', 'email': 'alvin@10gen.com'}Message: Added jstest for http://jira.mongodb.org/browse/SERVER-1896 |
| Comment by Alvin Richards (Inactive) [ 06/Oct/10 ] |
|
confirmed on a non-shared system that "n" is 1 as you would expect (see below). Will write a js test for this > db.test20101005.find( {x : { $lt : 60}} ).sort( { x:-1} ).limit(1).explain() } |
| Comment by Eliot Horowitz (Inactive) [ 06/Oct/10 ] |
|
Yes - please attach a full example w/o sharding with asserts (in js test style) |
| Comment by Eliot Horowitz (Inactive) [ 05/Oct/10 ] |
|
pretty sure that's notmal behavior when using limit(1) |