[SERVER-13124] Query with SORT_MERGE stage returns same document twice Created: 10/Mar/14 Updated: 10/Dec/14 Resolved: 11/Mar/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 2.6.0-rc1 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | J Rassi | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | 26qa | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
The example below shows a query that returns "n" larger than the size of the collection. Set up:
Issue a long-running series of updates:
Meanwhile, run the following query (and note that itcount() will return values greater than 10000, the number of documents in the collection):
Full explain:
|
| Comments |
| Comment by J Rassi [ 11/Mar/14 ] |
|
Resolving: works as designed. This behavior is a known consequence of our isolation semantics. Quoting from plan_stage.h: "Any data inserted, deleted, or modified during a yield that should be returned by a query may or may not be returned by that query. The query could return: nothing; the data before; the data after; or both the data before and the data after." In this case, the query is returning "the data before and the data after." The index scan returns the document, then the document is moved (and, with the diskloc change, the index entry is moved ahead of the index cursor), then the index scan encounters the same document again later in the btree and returns it a second time. |
| Comment by J Rassi [ 10/Mar/14 ] |
|
I filed this ticket originally against explain().n, but now I realize I can also reproduce this with itcount(), and that the index scan stages are also reporting "advanced" larger than the collection size. Updated title/description accordingly. |
| Comment by J Rassi [ 10/Mar/14 ] |
|
Likely culprit? https://github.com/mongodb/mongo/blob/25596dbf48b18a76d3d2cdfdf1fcf23a43e46316/src/mongo/db/exec/merge_sort.cpp#L171 "advanced" is incremented even when the stage returns NEED_TIME. |