Skip to content

Commit be2f858

Browse files
committed
SERVER-4494 add index version to explain output
1 parent ae18bbe commit be2f858

10 files changed

+27
-13
lines changed

src/mongo/db/exec/count_scan.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace mongo {
5656
_specificStats.keyPattern = _params.descriptor->keyPattern();
5757
_specificStats.indexName = _params.descriptor->indexName();
5858
_specificStats.isMultiKey = _params.descriptor->isMultikey(txn);
59+
_specificStats.indexVersion = _params.descriptor->version();
5960
}
6061

6162
void CountScan::initIndexCursor() {

src/mongo/db/exec/distinct_scan.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace mongo {
4141
using std::vector;
4242

4343
// static
44-
const char* DistinctScan::kStageType = "DISTINCT";
44+
const char* DistinctScan::kStageType = "DISTINCT_SCAN";
4545

4646
DistinctScan::DistinctScan(OperationContext* txn, const DistinctParams& params, WorkingSet* workingSet)
4747
: _txn(txn),
@@ -54,6 +54,7 @@ namespace mongo {
5454
_commonStats(kStageType) {
5555
_specificStats.keyPattern = _params.descriptor->keyPattern();
5656
_specificStats.indexName = _params.descriptor->indexName();
57+
_specificStats.indexVersion = _params.descriptor->version();
5758
}
5859

5960
void DistinctScan::initIndexCursor() {
@@ -255,7 +256,7 @@ namespace mongo {
255256

256257
PlanStageStats* DistinctScan::getStats() {
257258
_commonStats.isEOF = isEOF();
258-
auto_ptr<PlanStageStats> ret(new PlanStageStats(_commonStats, STAGE_DISTINCT));
259+
auto_ptr<PlanStageStats> ret(new PlanStageStats(_commonStats, STAGE_DISTINCT_SCAN));
259260
ret->specific.reset(new DistinctScanStats(_specificStats));
260261
return ret.release();
261262
}

src/mongo/db/exec/distinct_scan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace mongo {
108108

109109
virtual std::vector<PlanStage*> getChildren() const;
110110

111-
virtual StageType stageType() const { return STAGE_DISTINCT; }
111+
virtual StageType stageType() const { return STAGE_DISTINCT_SCAN; }
112112

113113
virtual PlanStageStats* getStats();
114114

src/mongo/db/exec/index_scan.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace mongo {
8484
_specificStats.keyPattern = _keyPattern;
8585
_specificStats.indexName = _params.descriptor->indexName();
8686
_specificStats.isMultiKey = _params.descriptor->isMultikey(_txn);
87+
_specificStats.indexVersion = _params.descriptor->version();
8788
}
8889

8990
void IndexScan::initIndexScan() {

src/mongo/db/exec/plan_stats.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ namespace mongo {
243243
};
244244

245245
struct CountScanStats : public SpecificStats {
246-
CountScanStats() : isMultiKey(false),
246+
CountScanStats() : indexVersion(0),
247+
isMultiKey(false),
247248
keysExamined(0) { }
248249

249250
virtual ~CountScanStats() { }
@@ -259,6 +260,8 @@ namespace mongo {
259260

260261
BSONObj keyPattern;
261262

263+
int indexVersion;
264+
262265
bool isMultiKey;
263266

264267
size_t keysExamined;
@@ -280,7 +283,7 @@ namespace mongo {
280283
};
281284

282285
struct DistinctScanStats : public SpecificStats {
283-
DistinctScanStats() : keysExamined(0) { }
286+
DistinctScanStats() : keysExamined(0), indexVersion(0) { }
284287

285288
virtual SpecificStats* clone() const {
286289
DistinctScanStats* specific = new DistinctScanStats(*this);
@@ -294,6 +297,8 @@ namespace mongo {
294297
std::string indexName;
295298

296299
BSONObj keyPattern;
300+
301+
int indexVersion;
297302
};
298303

299304
struct FetchStats : public SpecificStats {
@@ -356,7 +361,9 @@ namespace mongo {
356361
};
357362

358363
struct IndexScanStats : public SpecificStats {
359-
IndexScanStats() : isMultiKey(false),
364+
IndexScanStats() : indexVersion(0),
365+
direction(1),
366+
isMultiKey(false),
360367
yieldMovedCursor(0),
361368
dupsTested(0),
362369
dupsDropped(0),
@@ -382,6 +389,8 @@ namespace mongo {
382389

383390
BSONObj keyPattern;
384391

392+
int indexVersion;
393+
385394
// A BSON (opaque, ie. hands off other than toString() it) representation of the bounds
386395
// used.
387396
BSONObj indexBounds;

src/mongo/db/query/explain.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace {
121121
const CountScanStats* spec = static_cast<const CountScanStats*>(specific);
122122
return spec->keysExamined;
123123
}
124-
else if (STAGE_DISTINCT == type) {
124+
else if (STAGE_DISTINCT_SCAN == type) {
125125
const DistinctScanStats* spec = static_cast<const DistinctScanStats*>(specific);
126126
return spec->keysExamined;
127127
}
@@ -173,7 +173,7 @@ namespace {
173173
const CountScanStats* spec = static_cast<const CountScanStats*>(specific);
174174
ss << " " << spec->keyPattern;
175175
}
176-
else if (STAGE_DISTINCT == stage->stageType()) {
176+
else if (STAGE_DISTINCT_SCAN == stage->stageType()) {
177177
const DistinctScanStats* spec = static_cast<const DistinctScanStats*>(specific);
178178
ss << " " << spec->keyPattern;
179179
}
@@ -291,6 +291,7 @@ namespace mongo {
291291
bob->append("keyPattern", spec->keyPattern);
292292
bob->append("indexName", spec->indexName);
293293
bob->appendBool("isMultiKey", spec->isMultiKey);
294+
bob->append("indexVersion", spec->indexVersion);
294295
}
295296
else if (STAGE_DELETE == stats.stageType) {
296297
DeleteStats* spec = static_cast<DeleteStats*>(stats.specific.get());
@@ -345,6 +346,7 @@ namespace mongo {
345346
bob->append("keyPattern", spec->keyPattern);
346347
bob->append("indexName", spec->indexName);
347348
bob->appendBool("isMultiKey", spec->isMultiKey);
349+
bob->append("indexVersion", spec->indexVersion);
348350
bob->append("direction", spec->direction > 0 ? "forward" : "backward");
349351

350352
if ((topLevelBob->len() + spec->indexBounds.objsize()) > kMaxStatsBSONSize) {

src/mongo/db/query/planner_analysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ namespace mongo {
693693
coveredKeyObj = ixn->indexKeyPattern;
694694
QLOG() << "PROJECTION: covered via IXSCAN, using COVERED fast path";
695695
}
696-
else if (STAGE_DISTINCT == leafNodes[0]->getType()) {
696+
else if (STAGE_DISTINCT_SCAN == leafNodes[0]->getType()) {
697697
projType = ProjectionNode::COVERED_ONE_INDEX;
698698
DistinctNode* dn = static_cast<DistinctNode*>(leafNodes[0]);
699699
coveredKeyObj = dn->indexKeyPattern;

src/mongo/db/query/query_solution.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ namespace mongo {
678678
DistinctNode() { }
679679
virtual ~DistinctNode() { }
680680

681-
virtual StageType getType() const { return STAGE_DISTINCT; }
681+
virtual StageType getType() const { return STAGE_DISTINCT_SCAN; }
682682
virtual void appendToString(mongoutils::str::stream* ss, int indent) const;
683683

684684
// This stage is created "on top" of normal planning and as such the properties

src/mongo/db/query/stage_builder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ namespace mongo {
286286
if (NULL == childStage) { return NULL; }
287287
return new KeepMutationsStage(km->filter.get(), ws, childStage);
288288
}
289-
else if (STAGE_DISTINCT == root->getType()) {
289+
else if (STAGE_DISTINCT_SCAN == root->getType()) {
290290
const DistinctNode* dn = static_cast<const DistinctNode*>(root);
291291

292292
if (NULL == collection) {

src/mongo/db/query/stage_types.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ namespace mongo {
5151
STAGE_DELETE,
5252

5353
// If we're running a distinct, we only care about one value for each key. The distinct
54-
// stage is an ixscan with some key-skipping behvaior that only distinct uses.
55-
STAGE_DISTINCT,
54+
// scan stage is an ixscan with some key-skipping behvaior that only distinct uses.
55+
STAGE_DISTINCT_SCAN,
5656

5757
// Dummy stage used for receiving notifications of deletions during chunk migration.
5858
STAGE_NOTIFY_DELETE,

0 commit comments

Comments
 (0)