[SERVER-31858] explodeForSort() planning path can incorrectly produce a plan which obtains a sort via a multikey index scan Created: 07/Nov/17  Updated: 30/Oct/23  Resolved: 10/Nov/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.6.0-rc2
Fix Version/s: 3.6.0-rc4

Type: Bug Priority: Critical - P2
Reporter: David Storch Assignee: David Storch
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-19402 Change semantics of sorting by array ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 2017-11-13, Query 2017-12-04
Participants:
Case:

 Description   

As of the changes in SERVER-19402, a multikey field of an index cannot be used to provide a non-blocking sort. This is not correctly enforced in the explodeForSort() path of the planner's sort analysis phase. As a result, the planner produces an incorrect plan which does not sort array fields correctly according to the new semantics described in SERVER-19402:

> db.c.find();
{ "_id" : 0, "a" : [ { "b" : 0, "c" : 1 }, { "b" : 1, "c" : 2 } ] }
{ "_id" : 1, "a" : [ { "b" : 0, "c" : 2 }, { "b" : 1, "c" : 0 } ] }
{ "_id" : 2, "a" : [ { "b" : 0, "c" : 0 }, { "b" : 1, "c" : 1 } ] }
> db.c.createIndex({"a.b": 1, "a.c": 1})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 2,
	"numIndexesAfter" : 2,
	"note" : "all indexes already exist",
	"ok" : 1
}
 
// The sort order is incorrect since the _id:1 document should sort before _id:0.
> db.c.find({"a.b": 0 }).sort({"a.c": 1 });
{ "_id" : 2, "a" : [ { "b" : 0, "c" : 0 }, { "b" : 1, "c" : 1 } ] }
{ "_id" : 0, "a" : [ { "b" : 0, "c" : 1 }, { "b" : 1, "c" : 2 } ] }
{ "_id" : 1, "a" : [ { "b" : 0, "c" : 2 }, { "b" : 1, "c" : 0 } ] }



 Comments   
Comment by Githook User [ 10/Nov/17 ]

Author:

{'name': 'David Storch', 'username': 'dstorch', 'email': 'david.storch@10gen.com'}

Message: SERVER-31858 Fix explodeForSort() path to handle multikeyness correctly.
Branch: master
https://github.com/mongodb/mongo/commit/69ab9781d7a646a6029e5c46d340685e80e404fa

Generated at Thu Feb 08 04:28:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.