[SERVER-20641] Equality query on _id with a sort fails with an InternalError when routed through mongos Created: 25/Sep/15  Updated: 07/Oct/15  Resolved: 01/Oct/15

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: None
Fix Version/s: 3.1.9

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: YunHe Wang
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QuInt A (10/12/15)
Participants:

 Description   

This is a bug in the new mongos read path, so it only affects the master branch. It does not affect any stable versions.

The following script reproduces the problem:

(function() {
    'use strict';
 
    var st = new ShardingTest({shards: 1});
 
    var sdb = st.s.getDB("test");
    var coll = sdb.sortkey_internal_error;
 
    coll.drop();
    assert.writeOK(coll.insert({_id: 1, a: 2}));
 
    assert.eq(1, coll.find({_id: 1}).sort({a: 1}).itcount());
 
    st.stop();
})();

Looks like a bad interaction between idhack and sortKey meta-projection.



 Comments   
Comment by Githook User [ 01/Oct/15 ]

Author:

{u'username': u'yhjw88', u'name': u'Yunhe (John) Wang', u'email': u'yunhe.wang@mongodb.com'}

Message: SERVER-20641 Equality query on _id with sort now works on mongos
Branch: master
https://github.com/mongodb/mongo/commit/67a6459668ebfb47bf9b8fb43077d166618de26d

Comment by YunHe Wang [ 28/Sep/15 ]

It appears that the query plan for the find() on "_id" consists of just IDHACK on mongod, which makes sense since the sort basically does nothing if we're doing equality on "_id".

mongos still sends the $meta sortkey projection to the shards though, and since no SORTKEY_GENERATOR stage is added, the final PROJECT stage on the shards will fail. The simplest solution may be to add the SORTKEY_GENERATOR stage to be processed after the IDHACK stage if there is a $meta sortkey projection, but there could be a better solution.

Comment by David Storch [ 25/Sep/15 ]

Thanks to rstam for discovering this!

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