diff options
author | Hari Khalsa <hkhalsa@10gen.com> | 2014-04-08 13:47:34 -0400 |
---|---|---|
committer | Matt Kangas <matt.kangas@mongodb.com> | 2014-04-10 11:48:15 -0400 |
commit | f5544e542d72c990fe4a3588ad632dd3acefe40b (patch) | |
tree | eac3423dd9fcb738f4274995b6cce353b84aaaaa | |
parent | 758f9f60ff799a76d6373de6b8ce820ebbd72bfc (diff) | |
download | mongo-f5544e542d72c990fe4a3588ad632dd3acefe40b.tar.gz |
SERVER-13489 move disk reading out of index scan ctor
(cherry picked from commit 5f3174ac46b169a90e1e17a7327a21824609abbf)
-rw-r--r-- | src/mongo/db/exec/index_scan.cpp | 34 | ||||
-rw-r--r-- | src/mongo/db/exec/index_scan.h | 4 |
2 files changed, 20 insertions, 18 deletions
diff --git a/src/mongo/db/exec/index_scan.cpp b/src/mongo/db/exec/index_scan.cpp index b7af34c0573..fb0fa30ed45 100644 --- a/src/mongo/db/exec/index_scan.cpp +++ b/src/mongo/db/exec/index_scan.cpp @@ -50,31 +50,31 @@ namespace mongo { IndexScan::IndexScan(const IndexScanParams& params, WorkingSet* workingSet, const MatchExpression* filter) : _workingSet(workingSet), - _keyPattern(params.descriptor->keyPattern().getOwned()), _hitEnd(false), _filter(filter), - _shouldDedup(params.descriptor->isMultikey()), + _shouldDedup(true), _yieldMovedCursor(false), _params(params), - _btreeCursor(NULL) { - // Do not access index descriptor after construction. - const IndexDescriptor* descriptor = params.descriptor; - _params.descriptor = NULL; - invariant(descriptor); + _btreeCursor(NULL) { } - _iam = descriptor->getIndexCatalog()->getIndex(descriptor); + void IndexScan::initIndexScan() { + // Perform the possibly heavy-duty initialization of the underlying index cursor. + _iam = _params.descriptor->getIndexCatalog()->getIndex(_params.descriptor); + _keyPattern = _params.descriptor->keyPattern().getOwned(); if (_params.doNotDedup) { _shouldDedup = false; } + else { + _shouldDedup = _params.descriptor->isMultikey(); + } - // Fetch what we need from index descriptor now because details in index - // catalog (such as multi-key) might change during/after execution. - _specificStats.indexName = descriptor->infoObj()["name"].String(); - _specificStats.isMultiKey = descriptor->isMultikey(); - } + // We can't always access the descriptor in the call to getStats() so we pull + // the status-only information we need out here. + _specificStats.indexName = _params.descriptor->infoObj()["name"].String(); + _specificStats.isMultiKey = _params.descriptor->isMultikey(); - void IndexScan::initIndexCursor() { + // Set up the index cursor. CursorOptions cursorOptions; if (1 == _params.direction) { @@ -128,8 +128,8 @@ namespace mongo { ++_commonStats.works; if (NULL == _indexCursor.get()) { - // First call to work(). Perform cursor init. - initIndexCursor(); + // First call to work(). Perform possibly heavy init. + initIndexScan(); checkEnd(); } else if (_yieldMovedCursor) { @@ -334,6 +334,8 @@ namespace mongo { } PlanStageStats* IndexScan::getStats() { + // WARNING: this could be called even if the collection was dropped. Do not access any + // catalog information here. _commonStats.isEOF = isEOF(); // These specific stats fields never change. diff --git a/src/mongo/db/exec/index_scan.h b/src/mongo/db/exec/index_scan.h index f9f8f3b1ee9..8e5f4697910 100644 --- a/src/mongo/db/exec/index_scan.h +++ b/src/mongo/db/exec/index_scan.h @@ -95,9 +95,9 @@ namespace mongo { private: /** - * Initialize the underlying IndexCursor + * Initialize the underlying IndexCursor, grab information from the catalog for stats. */ - void initIndexCursor(); + void initIndexScan(); /** See if the cursor is pointing at or past _endKey, if _endKey is non-empty. */ void checkEnd(); |