summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec/count.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2018-10-30 12:30:20 -0400
committerDavid Storch <david.storch@10gen.com>2018-11-07 15:05:49 -0500
commitf0b39d9184094661fcaa1049531b80b5ad6b3995 (patch)
tree6fcab5eb450ca32fc7683de08bac184cf9dda15d /src/mongo/db/exec/count.cpp
parent56248d50536a25d63526662683b221df8137ab36 (diff)
downloadmongo-f0b39d9184094661fcaa1049531b80b5ad6b3995.tar.gz
SERVER-37446 Change PlanStages which don't require a collection to avoid keeping a Collection*.
In order to prevent COUNT stage from requiring a Collection*, splits fast count into a new RECORD_STORE_FAST_COUNT stage.
Diffstat (limited to 'src/mongo/db/exec/count.cpp')
-rw-r--r--src/mongo/db/exec/count.cpp47
1 files changed, 4 insertions, 43 deletions
diff --git a/src/mongo/db/exec/count.cpp b/src/mongo/db/exec/count.cpp
index 3fa907b177e..15d6ec5baff 100644
--- a/src/mongo/db/exec/count.cpp
+++ b/src/mongo/db/exec/count.cpp
@@ -51,62 +51,23 @@ CountStage::CountStage(OperationContext* opCtx,
CountStageParams params,
WorkingSet* ws,
PlanStage* child)
- : PlanStage(kStageType, opCtx),
- _collection(collection),
- _params(std::move(params)),
- _leftToSkip(_params.skip),
- _ws(ws) {
- if (child)
- _children.emplace_back(child);
+ : PlanStage(kStageType, opCtx), _params(std::move(params)), _leftToSkip(_params.skip), _ws(ws) {
+ invariant(child);
+ _children.emplace_back(child);
}
bool CountStage::isEOF() {
- if (_specificStats.recordStoreCount) {
- return true;
- }
-
if (_params.limit > 0 && _specificStats.nCounted >= _params.limit) {
return true;
}
- return !_children.empty() && child()->isEOF();
-}
-
-void CountStage::recordStoreCount() {
- invariant(_collection);
- long long nCounted = _collection->numRecords(getOpCtx());
-
- if (0 != _params.skip) {
- nCounted -= _params.skip;
- if (nCounted < 0) {
- nCounted = 0;
- }
- }
-
- long long limit = _params.limit;
- if (limit < 0) {
- limit = -limit;
- }
-
- if (limit < nCounted && 0 != limit) {
- nCounted = limit;
- }
-
- _specificStats.nCounted = nCounted;
- _specificStats.nSkipped = _params.skip;
- _specificStats.recordStoreCount = true;
+ return child()->isEOF();
}
PlanStage::StageState CountStage::doWork(WorkingSetID* out) {
// This stage never returns a working set member.
*out = WorkingSet::INVALID_ID;
- if (_params.useRecordStoreCount) {
- invariant(_collection);
- recordStoreCount();
- return PlanStage::IS_EOF;
- }
-
if (isEOF()) {
_commonStats.isEOF = true;
return PlanStage::IS_EOF;