diff options
author | Kevin Matulef <matulef@10gen.com> | 2012-10-16 14:59:11 -0400 |
---|---|---|
committer | Kevin Matulef <matulef@10gen.com> | 2012-10-16 15:00:53 -0400 |
commit | 6f2893e002bd87963145124c96bc35a6fb2c30fc (patch) | |
tree | c003f7d8ea06d9f51357483f77a57f0473b651ef | |
parent | 6cacecacdb9870cbb3013ce6cc87c6f39b19335b (diff) | |
download | mongo-6f2893e002bd87963145124c96bc35a6fb2c30fc.tar.gz |
SERVER-5858 temporary fix so hashed indexes work with $in queries
-rw-r--r-- | jstests/hashindex1.js | 12 | ||||
-rw-r--r-- | src/mongo/db/queryoptimizer.cpp | 8 |
2 files changed, 11 insertions, 9 deletions
diff --git a/jstests/hashindex1.js b/jstests/hashindex1.js index 3af8c40c314..cc7ed1b08be 100644 --- a/jstests/hashindex1.js +++ b/jstests/hashindex1.js @@ -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"}; diff --git a/src/mongo/db/queryoptimizer.cpp b/src/mongo/db/queryoptimizer.cpp index 3e84483ea9b..4baf29a5f7b 100644 --- a/src/mongo/db/queryoptimizer.cpp +++ b/src/mongo/db/queryoptimizer.cpp @@ -1611,7 +1611,13 @@ doneCheckOrder: // 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 ) { |