[SERVER-8564] Clean up unneeded code for $natural hint overriding $natural sort Created: 14/Feb/13  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Aaron Staple Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: neweng, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-8561 Query with sort ($natural:1) is repor... Closed
Related
related to SERVER-6979 hint with { $natural:-1 } returns doc... Closed
related to SERVER-8607 add support for natural order sorting... Closed
Assigned Teams:
Query Optimization
Backwards Compatibility: Minor Change
Participants:

 Description   

Right now the only way to return documents in natural order is to use a collection scan cursor (not an index cursor). And, currently, if both an index hint and natural ordering are specified for a query, the hint will supersede the natural ordering spec and the results will not be returned in natural order. Instead, hinting an index that cannot be used to retrieve results in natural order should produce an error.

Test

c = db.c;
c.drop();
c.ensureIndex( { a:1 } );
c.save( { a:2 } );
c.save( { a:1 } );
 
printjson( c.find( { a:{ $gt:0 } } ).sort( { $natural:1 } ).hint( { a:1 } ).toArray() );
printjson( c.find( { a:{ $gt:0 } } ).sort( { $natural:1 } ).hint( { a:1 } ).explain() );



 Comments   
Comment by J Rassi [ 03/Feb/16 ]

After we resolved this ticket, I found related code in query_planner.cpp that could use cleaning up. Re-opening this ticket to track that work.

Comment by Tess Avitabile (Inactive) [ 03/Feb/16 ]

Hint no longer overrides natural sort. Now a hint that is inconsistent with a natural sort is an error. A hint is inconsistent with a natural sort if it uses an index or is a natural sort in the opposite direction.

Comment by Githook User [ 03/Feb/16 ]

Author:

{u'username': u'tessavitabile', u'name': u'Tess Avitabile', u'email': u'tess.avitabile@mongodb.com'}

Message: SERVER-8564 An index hint inconsistent with requested natural order sort should be an error
Branch: master
https://github.com/mongodb/mongo/commit/bb2f3aebc4c4ce5fd15c44ebca6d66dc0542562d

Comment by Githook User [ 03/Feb/16 ]

Author:

{u'username': u'tessavitabile', u'name': u'Tess Avitabile', u'email': u'tess.avitabile@mongodb.com'}

Message: SERVER-8564 Clean up CanonicalQuery::isValid()
Branch: master
https://github.com/mongodb/mongo/commit/407457dc34ea5afc3b983096c80959815b888632

Comment by Aaron Staple [ 18/Feb/13 ]

Natural order is not the same as disk loc order.

Comment by Eliot Horowitz (Inactive) [ 18/Feb/13 ]

Don't think this should error, should just use the index and then re-sort.

Generated at Thu Feb 08 03:17:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.