[SERVER-22041] Count command does not respect hint if query predicate is empty Created: 31/Dec/15  Updated: 18/Apr/16  Resolved: 05/Feb/16

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

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: Charlie Swanson
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Major Change
Operating System: ALL
Sprint: Query 10 (02/22/16)
Participants:

 Description   

The count command does not respect the user-specified hint, if an empty query predicate is specified.

This is due to a bug in CountStage::work(), which fails to check for a non-empty hint before deciding to apply the "trivial count" optimization.

Reproduce as follows:

> db.foo.drop()
true
> db.foo.ensureIndex({a: 1}, {sparse: true})
{
	"createdCollectionAutomatically" : true,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.foo.insert({})
WriteResult({ "nInserted" : 1 })
> db.foo.find().hint({a: 1}).itcount()
0
> db.foo.find().hint({a: 1}).count()
1  // Unexpected: should return 0 instead.
>



 Comments   
Comment by Githook User [ 18/Apr/16 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: CXX-897 Account for SERVER-22041 changes in test
Branch: legacy
https://github.com/mongodb/mongo-cxx-driver/commit/a95f89aa9cb13e0f905a302554e2e6b0e2098a1e

Comment by Charlie Swanson [ 05/Feb/16 ]

This was fixed with ebc481d27e408d8608075a61eba2a68be43c1314 as part of SERVER-20536.

Comment by Charlie Swanson [ 02/Feb/16 ]

This should be resolved by SERVER-20536. I will close this as a duplicate once that fix is committed if it is verified to also fix this.

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