[SERVER-480] figure out what to do with sorting by array sub-field Created: 12/Dec/09  Updated: 12/Jul/16  Resolved: 03/Jun/11

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: 1.9.1

Type: Task Priority: Critical - P2
Reporter: Eliot Horowitz (Inactive) Assignee: Aaron Staple
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-8152 aggregation array sort differs from q... Closed
related to SERVER-429 btree change (Sorting and other) mast... Closed
related to SERVER-19402 Change semantics of sorting by array ... Closed
Participants:

 Description   

the ensureIndex changes the output, which is bad.
not sure what should be correct, but having an index shouldn't change output.

db.foo.drop()
db.foo.save( { a : [

{ x : 2 }

] } )
db.foo.save( { a : [

{ x : 1 }

] } )
db.foo.save( { a : [

{ x : 3 }

] } )
db.foo.ensureIndex(

{ "a.x" : 1 }

)
db.foo.find().sort(

{ "a.x" : 1 }

).forEach( printjson );



 Comments   
Comment by auto [ 02/Jun/11 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-480 SERVER-2884 Perform in memory sorts by generating keys suitable for an index
Branch: master
https://github.com/mongodb/mongo/commit/70fbe10acfeb620022dd949a9ee9e90a3f683d32

Comment by auto [ 19/Apr/11 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-480 test
Branch: master
https://github.com/mongodb/mongo/commit/af93c8bb91d4a7a2ce25d8b81bc08a01f52cdc46

Comment by Remon van Vliet [ 01/Apr/11 ]

I agree that the indexed behaviour is the most intuitive solution and that the non-indexed implementation is the one that needs changing. I recently ran into this issue so I'm curious to see what the status is and how the expected implementation is going to work.

Comment by Eliot Horowitz (Inactive) [ 12/Dec/09 ]

Right - that's what will happen if its indexed right now.
Which I think is correct

Comment by Valentin [ 12/Dec/09 ]

db.foo.save( { a : [

{ x : 2 }

,

{ x : 3 }

] } )
db.foo.save( { a : [

{ x : 1 }

,

{ x : 4 }

] } )
db.foo.save( { a : [

{ x : 3 }

,

{ x : 2 }

] } )
db.foo.ensureIndex(

{ "a.x" : 1 }

)
db.foo.find().sort(

{ "a.x" : 1 }

).forEach( printjson );

what do it sort? I think the most intuitive will be sorting by the biggest/the smallest of all of a.x (depending on sort direction).

But It means what

db.foo.find().sort(

{ "a.x" : 1 }

)

can be not equal to reversed

db.foo.find().sort(

{ "a.x" : -1 }

)

I don't think it's a big deal, but it depends on how is sorting implemented

Generated at Thu Feb 08 02:54:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.