Permalink
Browse files

add comment and test for query optimizer failed yield of a cached pla…

…n with retry
  • Loading branch information...
1 parent dd62235 commit 716dc72fc03be867c1166640f24f335e71607157 @astaple astaple committed Dec 14, 2011
Showing with 29 additions and 1 deletion.
  1. +2 −1 db/queryoptimizer.cpp
  2. +27 −0 jstests/queryoptimizer5.js
View
@@ -553,6 +553,7 @@ namespace mongo {
if ( _bestGuessOnly || res->complete() || _plans.size() > 1 )
return res;
// A cached plan was used, so clear the plan for this query pattern and retry the query without a cached plan.
+ // Carefull here, as the namespace may have been dropped.
QueryUtilIndexed::clearIndexesForPatterns( *_frsp, _order );
init();
}
@@ -667,7 +668,7 @@ namespace mongo {
int micros = ClientCursor::suggestYieldMicros();
if ( micros <= 0 )
return;
-
+
if ( !prepareToYield() )
return;
View
@@ -0,0 +1,27 @@
+// Don't crash attempting to retry additional query plans if a recorded plan failed because a cursor was dropped.
+
+t = db.jstests_queryoptimizer5;
+t.drop();
+
+function reset() {
+ t.drop();
+ for( var i = 0; i < 5000; ++i ) {
+ t.save({a:i,b:i});
+ }
+ t.ensureIndex({a:1});
+ t.ensureIndex({b:1});
+}
+
+s = startParallelShell( "for( i = 0; i < 30; ++i ) { sleep( 200 ); db.jstests_queryoptimizer5.drop(); }" );
+
+for( var i = 0; i < 10; ++i ) {
+ try {
+ reset();
+ t.find( {$or:[{a:{$gte:0},b:{$gte:0}}]} ).batchSize( 10000 ).itcount();
+ t.find( {$or:[{a:{$gte:0},b:{$gte:0}}]} ).batchSize( 10000 ).itcount();
+ } catch (e) {
+// printjson(e);
+ }
+}
+
+s();

0 comments on commit 716dc72

Please sign in to comment.