For certain distinct queries, the distinct scan query stage can scan many index keys between returning results. Distinct queries that generate inexact bounds and encounter non-matching index entries (and thus generate a call to skip() on the underlying index cursor) are affected. As a result, the distinct query can scan a large index range without yielding its read lock.
To reproduce, run the following shell snippet. The distinct query on the third line will scan the complete {a: 1, b: 1} index without yielding.
for (i=0; i<1000000; i++) { db.foo.insert({a: i, b: 1}); } db.foo.ensureIndex({a: 1, b: 1}); db.foo.distinct("a", {a: {$ne: 0}, b: 0});
Regression introduced in 2.6.0.
- related to
-
SERVER-15152 When evaluating plans, some index candidates cause complete index scan
- Closed