0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-14792 count with a bad hint should fail, even if there is no query predicate

This commit is contained in:
David Storch 2015-01-26 15:08:43 -05:00
parent 5145903fc2
commit c59a144b57
2 changed files with 13 additions and 6 deletions

View File

@ -24,3 +24,8 @@ assert.eq( 0, t.find( { i: 1 } ).hint( { x: 1 } ).count(), "E" );
assert.eq( 2, t.find().hint( { x: 1 } ).count(), "F" );
assert.eq( 1, t.find( { i: 1 } ).hint( { _id: 1 } ).count(), "G" );
assert.throws( function() { t.find( { i: 1 } ).hint( { bad: 1, hint: 1 } ).count(); } );
// SERVER-14792: bad hints should cause the count to fail, even if there is no query predicate.
assert.eq( 2, t.find().hint( { i: 1 } ).count(), "H" );
assert.throws( function() { t.find().hint( { bad: 1, hint: 1 } ).count() } );
assert.throws( function() { t.find().hint( "BAD HINT" ).count() } );

View File

@ -955,17 +955,19 @@ namespace mongo {
QuerySolution* querySolution;
// If collection exists and the query is empty, no additional canonicalization is needed.
if (collection && request.query.isEmpty()) {
// If the query is empty, then we can determine the count by just asking the collection
// for its number of records. This is implemented by the CountStage, and we don't need
// to create a child for the count stage in this case.
// If the query is empty, then we can determine the count by just asking the collection
// for its number of records. This is implemented by the CountStage, and we don't need
// to create a child for the count stage in this case.
//
// If there is a hint, then we can't use a trival count plan as described above.
if (collection && request.query.isEmpty() && request.hint.isEmpty()) {
root = new CountStage(txn, collection, request, ws.get(), NULL);
return PlanExecutor::make(txn, ws.release(), root, request.ns, yieldPolicy, execOut);
}
auto_ptr<CanonicalQuery> cq;
if (!request.query.isEmpty()) {
// If query is not empty, canonicalize it before working with collection.
if (!request.query.isEmpty() || !request.hint.isEmpty()) {
// If query or hint is not empty, canonicalize the query before working with collection.
typedef MatchExpressionParser::WhereCallback WhereCallback;
CanonicalQuery* rawCq = NULL;
Status canonStatus = CanonicalQuery::canonicalize(