[SERVER-30696] $sort in aggregate is super slow Created: 16/Aug/17  Updated: 07/Sep/17  Resolved: 16/Aug/17

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.4.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jesper Erik Bendtsen Assignee: Mark Agarunov
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File explain.txt    
Issue Links:
Duplicate
duplicates SERVER-7568 Aggregation framework favors non-bloc... Closed
Operating System: ALL
Participants:

 Description   

I have a collection with about 75.000 docs

Indexes:
ad.guid_1
unitUuid_1

This query takes about 1-2 milliseconds and gives 1 hit:

db.getCollection('xxx').aggregate([
    { $match: { "ad.guid": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } }
])

This query takes about 180 milliseconds and gives 1 hit:

db.getCollection('xxx').aggregate([
    { $match: { "ad.guid": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" } },
    { $sort: { "unitUuid": 1 } }
])

Why is it so slow with $sort?



 Comments   
Comment by Mark Agarunov [ 16/Aug/17 ]

Hello jesperbendtsen83@gmail.com,

Thank you for the report. Looking over your description and example of the behavior, I believe this behavior has the same cause as SERVER-7568, where the query planner prefers non-blocking sorts, sometimes causing it to use slower plans. I've closed this ticket as a duplicate of SERVER-7568, please watch that ticket for updates on this issue.

Thanks,
Mark

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