-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
Query
-
ALL
The SORT_MERGE query stage uses BSONElement::woCompare() to compare WorkingSetMembers from its child stages, instead using the SortStageKeyGenerator to generate sort keys. As a result, query plans that use the SORT_MERGE stage which are performing a bounded sort on a multi-key field can generate results in incorrect order. This issue is quite similar to SERVER-11878.
To reproduce:
> db.bar.drop() true > db.bar.insert({_id: 0, a: [8], b: 1}) WriteResult({ "nInserted" : 1 }) > db.bar.insert({_id: 1, a: [6, 10], b: 1}) WriteResult({ "nInserted" : 1 }) > db.bar.ensureIndex({a: 1}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.bar.find({$or: [{a: {$gt: 7}}, {a: {$gt: 6}}]}).sort({a: 1}) // SORT_MERGE not used: correct order. { "_id" : 0, "a" : [ 8 ], "b" : 1 } { "_id" : 1, "a" : [ 6, 10 ], "b" : 1 } > db.bar.find({$or: [{a: {$gt: 7}, b: 1}, {a: {$gt: 6}, b: 1}]}).sort({a: 1}) // SORT_MERGE used: incorrect order. { "_id" : 1, "a" : [ 6, 10 ], "b" : 1 } { "_id" : 0, "a" : [ 8 ], "b" : 1 }
- is related to
-
SERVER-19397 Results in incorrect order for complex $or query with bounded sort on multi-key field when SORT plan used
- Closed
-
SERVER-19402 Change semantics of sorting by array fields in find and aggregate
- Closed
- related to
-
SERVER-11878 Results in incorrect order for sharded query with bounded sort on multi-key field
- Closed