diff options
Diffstat (limited to 'src/mongo/db/exec/count.h')
-rw-r--r-- | src/mongo/db/exec/count.h | 150 |
1 files changed, 76 insertions, 74 deletions
diff --git a/src/mongo/db/exec/count.h b/src/mongo/db/exec/count.h index 4a2954ad140..0c7a9c0e2fd 100644 --- a/src/mongo/db/exec/count.h +++ b/src/mongo/db/exec/count.h @@ -34,102 +34,104 @@ namespace mongo { - /** - * A description of a request for a count operation. Copyable. - */ - struct CountRequest { - // Namespace to operate on (e.g. "foo.bar"). - std::string ns; +/** + * A description of a request for a count operation. Copyable. + */ +struct CountRequest { + // Namespace to operate on (e.g. "foo.bar"). + std::string ns; - // A predicate describing the set of documents to count. - // - // NOTE: - // Parsing the raw BSON to our AST is left for later so that the parse method does not - // have to look at the catalog. Specifically, creating a CanonicalQuery requires a - // Collection* due to the WhereCallback, and we'd rather not have the parse method require - // a Collection*. - BSONObj query; + // A predicate describing the set of documents to count. + // + // NOTE: + // Parsing the raw BSON to our AST is left for later so that the parse method does not + // have to look at the catalog. Specifically, creating a CanonicalQuery requires a + // Collection* due to the WhereCallback, and we'd rather not have the parse method require + // a Collection*. + BSONObj query; - // Indicates to the query planner that it should generate a count plan using a - // particular index. - BSONObj hint; + // Indicates to the query planner that it should generate a count plan using a + // particular index. + BSONObj hint; - // An integer limiting the number of documents to count. - long long limit; + // An integer limiting the number of documents to count. + long long limit; - // An integer indicating to not include the first n documents in the count. - long long skip; + // An integer indicating to not include the first n documents in the count. + long long skip; - // Whether this is an explain of a count. - bool explain; - }; + // Whether this is an explain of a count. + bool explain; +}; - /** - * 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. - * - * This should not be confused with the CountScan stage. CountScan is a special - * index access stage which can optimize index access for count operations in - * some cases. On the other hand, *every* count op has a CountStage at its root. - * - * Only returns NEED_TIME until hitting EOF. The count result can be obtained by examining - * the specific stats. - */ - class CountStage : public PlanStage { - public: - CountStage(OperationContext* txn, - Collection* collection, - const CountRequest& request, - WorkingSet* ws, - PlanStage* child); +/** + * 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. + * + * This should not be confused with the CountScan stage. CountScan is a special + * index access stage which can optimize index access for count operations in + * some cases. On the other hand, *every* count op has a CountStage at its root. + * + * Only returns NEED_TIME until hitting EOF. The count result can be obtained by examining + * the specific stats. + */ +class CountStage : public PlanStage { +public: + CountStage(OperationContext* txn, + Collection* collection, + const CountRequest& request, + WorkingSet* ws, + PlanStage* child); - virtual ~CountStage(); + virtual ~CountStage(); - virtual bool isEOF(); - virtual StageState work(WorkingSetID* out); + virtual bool isEOF(); + virtual StageState work(WorkingSetID* out); - virtual void saveState(); - virtual void restoreState(OperationContext* opCtx); - virtual void invalidate(OperationContext* txn, const RecordId& dl, InvalidationType type); + virtual void saveState(); + virtual void restoreState(OperationContext* opCtx); + virtual void invalidate(OperationContext* txn, const RecordId& dl, InvalidationType type); - virtual std::vector<PlanStage*> getChildren() const; + virtual std::vector<PlanStage*> getChildren() const; - virtual StageType stageType() const { return STAGE_COUNT; } + virtual StageType stageType() const { + return STAGE_COUNT; + } - PlanStageStats* getStats(); + PlanStageStats* getStats(); - virtual const CommonStats* getCommonStats(); + virtual const CommonStats* getCommonStats(); - virtual const SpecificStats* getSpecificStats(); + virtual const SpecificStats* getSpecificStats(); - static const char* kStageType; + static const char* kStageType; - private: - /** - * Computes the count in the case of an empty query, applying the skip and - * limit if necessary. The result is stored in '_specificStats'. - */ - void trivialCount(); +private: + /** + * Computes the count in the case of an empty query, applying the skip and + * limit if necessary. The result is stored in '_specificStats'. + */ + void trivialCount(); - // Transactional context for read locks. Not owned by us. - OperationContext* _txn; + // Transactional context for read locks. Not owned by us. + OperationContext* _txn; - // The collection over which we are counting. - Collection* _collection; + // The collection over which we are counting. + Collection* _collection; - CountRequest _request; + CountRequest _request; - // The number of documents that we still need to skip. - long long _leftToSkip; + // The number of documents that we still need to skip. + long long _leftToSkip; - // The working set used to pass intermediate results between stages. Not owned - // by us. - WorkingSet* _ws; + // The working set used to pass intermediate results between stages. Not owned + // by us. + WorkingSet* _ws; - boost::scoped_ptr<PlanStage> _child; + boost::scoped_ptr<PlanStage> _child; - CommonStats _commonStats; - CountStats _specificStats; - }; + CommonStats _commonStats; + CountStats _specificStats; +}; } // namespace mongo |