[SERVER-35851] Consider checking whether the array passed to $in is already sorted before calling std::sort Created: 27/Jun/18  Updated: 29/Oct/23  Resolved: 29/Jun/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 4.0.1, 4.1.1

Type: Improvement Priority: Major - P3
Reporter: Nicholas Zolnierz Assignee: Nicholas Zolnierz
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.0
Sprint: Query 2018-07-02, Query 2018-07-16
Participants:
Linked BF Score: 0

 Description   

As part of SERVER-35693, parsing a $in query will always sort the array argument before constructing a boost::flat_set. This greatly benefits the case where the number of elements is very large (>10k) and is unsorted, however as a side effect it hurts performance when the array is already sorted.

One option would be to add an optimization for the sorted case by checking std::is_sorted before sorting the array.



 Comments   
Comment by Githook User [ 06/Jul/18 ]

Author:

{'username': 'nzolnierzmdb', 'name': 'Nick Zolnierz', 'email': 'nicholas.zolnierz@mongodb.com'}

Message: SERVER-35851: Check whether the array passed to $in is sorted before calling std::sort

(cherry picked from commit a4dfe1ce6b04fceff0794d842b791951990d187c)
Branch: v4.0
https://github.com/mongodb/mongo/commit/34af8b270e361b6756dca30092a39fb51ef5c0d2

Comment by Githook User [ 29/Jun/18 ]

Author:

{'username': 'nzolnierzmdb', 'name': 'Nick Zolnierz', 'email': 'nicholas.zolnierz@mongodb.com'}

Message: SERVER-35851: Check whether the array passed to $in is sorted before calling std::sort
Branch: master
https://github.com/mongodb/mongo/commit/a4dfe1ce6b04fceff0794d842b791951990d187c

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