Permalink
Browse files

SERVER-5858 temporary fix so hashed indexes work with $in queries

  • Loading branch information...
1 parent 6caceca commit 6f2893e002bd87963145124c96bc35a6fb2c30fc @matulef matulef committed Oct 16, 2012
Showing with 11 additions and 9 deletions.
  1. +4 −8 jstests/hashindex1.js
  2. +7 −1 src/mongo/db/queryoptimizer.cpp
View
@@ -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"};
@@ -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 ) {

0 comments on commit 6f2893e

Please sign in to comment.