diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2016-02-02 14:34:33 -0500 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2016-02-04 19:38:27 -0500 |
commit | ebc481d27e408d8608075a61eba2a68be43c1314 (patch) | |
tree | 15a687d4a35907b4ed9cad98df591b9e31b26f78 /src/mongo/db/exec/count.h | |
parent | 8d9c1a2cae9969ed5e5524e7f23f0a2bc3376982 (diff) | |
download | mongo-ebc481d27e408d8608075a61eba2a68be43c1314.tar.gz |
SERVER-20536 Ignore comment field when planning counts.
Diffstat (limited to 'src/mongo/db/exec/count.h')
-rw-r--r-- | src/mongo/db/exec/count.h | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/mongo/db/exec/count.h b/src/mongo/db/exec/count.h index e083eb59aff..56cdbe6614c 100644 --- a/src/mongo/db/exec/count.h +++ b/src/mongo/db/exec/count.h @@ -34,6 +34,30 @@ namespace mongo { +struct CountStageParams { + CountStageParams(const CountRequest& request, bool useRecordStoreCount) + : nss(request.getNs()), + limit(request.getLimit()), + skip(request.getSkip()), + useRecordStoreCount(useRecordStoreCount) {} + + // Namespace to operate on (e.g. "foo.bar"). + NamespaceString nss; + + // An integer limiting the number of documents to count. 0 means no limit. + long long limit; + + // An integer indicating to not include the first n documents in the count. 0 means no skip. + long long skip; + + // True if this count stage should just ask the record store for a count instead of computing + // one itself. + // + // Note: This strategy can lead to inaccurate counts on certain storage engines (including + // WiredTiger). + bool useRecordStoreCount; +}; + /** * Stage used by the count command. This stage sits at the root of a plan tree * and counts the number of results returned by its child stage. @@ -49,7 +73,7 @@ class CountStage final : public PlanStage { public: CountStage(OperationContext* txn, Collection* collection, - const CountRequest& request, + CountStageParams params, WorkingSet* ws, PlanStage* child); @@ -68,15 +92,17 @@ public: private: /** - * Computes the count in the case of an empty query, applying the skip and - * limit if necessary. The result is stored in '_specificStats'. + * Asks the record store for the count, applying the skip and limit if necessary. The result is + * stored in '_specificStats'. + * + * This is only valid if the query and hint are both empty. */ - void trivialCount(); + void recordStoreCount(); // The collection over which we are counting. Collection* _collection; - CountRequest _request; + CountStageParams _params; // The number of documents that we still need to skip. long long _leftToSkip; |