[SERVER-33895] Not needed SORT_KEY_GENERATOR in aggregation explain output Created: 14/Mar/18  Updated: 25/Apr/18  Resolved: 25/Apr/18

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

Type: Bug Priority: Major - P3
Reporter: Renato Riccio Assignee: Charlie Swanson
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-29449 Explain of find command does not tran... Backlog
Operating System: ALL
Steps To Reproduce:

sh.enableSharding("test")
 
sh.shardCollection("test.sharded",{a:1})
for(i=0;i<100;i++){db.sharded.insert({a:i})}
for(i=0;i<10;i++){sh.splitFind("test.sharded",{a:i})}
// Wait for the balancer to distirbute the chunk
 
// No sort stage
db.sharded.explain().find().sort({a:1})
 
// SORT_KEY_GENERATOR stage
db.sharded.explain().aggregate([{$sort:{a:1}}])
 
// SORT_KEY_GENERATOR is not shown if the aggregation impacts only one shard
db.sharded.explain().aggregate([{$match:{a:{$gt:50}}},{$sort:{a:1}}] )

Sprint: Query 2018-05-07
Participants:

 Description   

In 3.6 the aggregation explain output shows a SORT_KEY_GENERATOR stage even when it is not needed.



 Comments   
Comment by Charlie Swanson [ 25/Apr/18 ]

It looks like this is simply a bug in the explain output. In the reproduction script the output for the following line does not include a SORT_KEY_GENERATOR stage:

db.sharded.explain().find().sort({a: 1});

This is because the explain path on mongos diverges from the regular, non-explain path pretty early. In particular, the non-explain path will transform the query sent to the shards in transformQueryForShards. This transformation does not happen in the explain path, and causes us to leave off the projection {$sortKey: 1} which will signal to the shards that we intend to merge the sorted output on mongos.

I think this is a different symptom, but the same root cause as the bug described in SERVER-29449. I'll clean up and generalize that ticket, then close this one as a duplicate.

Comment by Asya Kamsky [ 09/Apr/18 ]

Aggregation needs the sort keys to merge sorted streams on mongos.

The real question seems to be why doesn't find show the same?

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