Skip to content

Commit

Permalink
SERVER-5858 temporary fix so hashed indexes work with $in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Matulef committed Oct 16, 2012
1 parent 6caceca commit 6f2893e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 4 additions & 8 deletions jstests/hashindex1.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ assert.neq( t.find({c : 1}).explain().cursor ,
cursorname ,
"using irrelevant hashed cursor");

/* This test should work but doesn't yet because of the way queries are
* simplified before being passed to 'suitability'. When this issue is
* fixed this test can be added.
*
assert.eq( t.find({a : {$in : [1,2]}}).explain()["cursor"] ,
cursorname ,
"not using hashed cursor");
*/
assert.eq( t.find({a : {$in : [1,2]}}).explain()["cursor"] ,
"BtreeCursor a_hashed multi" ,
"not using hashed cursor");


//test creation of index based on hash of _id index
var goodspec2 = {'_id' : "hashed"};
Expand Down
8 changes: 7 additions & 1 deletion src/mongo/db/queryoptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,13 @@ namespace mongo {
// No matches are possible in the index so the index may be useful.
return true;
}
return d->idx( idxNo ).getSpec().suitability( frsp.simplifiedQueryForIndex( d, idxNo, keyPattern ), order ) != USELESS;
// Hashed index types can't use simplified query bounds, since they could turn equalities
// into ranges, e.g.{$in : [1,2] } into {$gte : 1 , $lte : 2}
// TODO: refactor suitability to take a FieldRangeSetPair, and get rid of this special case
// See SERVER-5858.
BSONObj query = ( d->idx( idxNo ).getSpec().getTypeName() == "hashed" ) ?
frsp.originalQuery() : frsp.simplifiedQueryForIndex( d, idxNo, keyPattern );
return d->idx( idxNo ).getSpec().suitability( query, order ) != USELESS;
}

void QueryUtilIndexed::clearIndexesForPatterns( const FieldRangeSetPair &frsp, const BSONObj &order ) {
Expand Down

0 comments on commit 6f2893e

Please sign in to comment.