diff options
Diffstat (limited to 'src/mongo/db/ops/count.cpp')
-rw-r--r-- | src/mongo/db/ops/count.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/mongo/db/ops/count.cpp b/src/mongo/db/ops/count.cpp index 713c40edb5a..c63b4e5d8c6 100644 --- a/src/mongo/db/ops/count.cpp +++ b/src/mongo/db/ops/count.cpp @@ -26,6 +26,33 @@ #include "mongo/util/elapsed_tracker.h" namespace mongo { + + namespace { + + /** + * Specialized Cursor creation rules that the count operator provides to the query + * processing system. These rules limit the performance overhead when counting index keys + * matching simple predicates. See SERVER-1752. + */ + class CountPlanPolicies : public QueryPlanSelectionPolicy { + + virtual string name() const { return "CountPlanPolicies"; } + + virtual bool requestMatcher() const { + // Avoid using a Matcher when a Cursor will exactly match a query. + return false; + } + + virtual bool requestIntervalCursor() const { + // Request use of an IntervalBtreeCursor when the index bounds represent a single + // btree interval. This Cursor implementation is optimized for performing counts + // between two endpoints. + return true; + } + + } _countPlanPolicies; + + } long long runCount( const char *ns, const BSONObj &cmd, string &err, int &errCode ) { Client::Context cx(ns); @@ -53,11 +80,7 @@ namespace mongo { NamespaceDetailsTransient::getCursor( ns, query, BSONObj(), - QueryPlanSelectionPolicy::any(), - // Avoid using a Matcher when a Cursor can - // exactly match the query using a - // FieldRangeVector. See SERVER-1752. - false /* requestMatcher */ ); + _countPlanPolicies ); ClientCursor::Holder ccPointer; ElapsedTracker timeToStartYielding( 256, 20 ); try { |