Skip to content

Commit

Permalink
SERVER-16512 add comment explaining 'docsExamined' tracking in the Fe…
Browse files Browse the repository at this point in the history
…tchStage
  • Loading branch information
dstorch committed Jan 15, 2015
1 parent e9a439c commit e5800d5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/mongo/db/exec/fetch.cpp
Expand Up @@ -186,6 +186,20 @@ namespace mongo {
PlanStage::StageState FetchStage::returnIfMatches(WorkingSetMember* member,
WorkingSetID memberID,
WorkingSetID* out) {
// We consider "examining a document" to be every time that we pass a document through
// a filter by calling Filter::passes(...) below. Therefore, the 'docsExamined' metric
// is not always equal to the number of documents that were fetched from the collection.
// In particular, we can sometimes generate plans which have two fetch stages. The first
// one actually grabs the document from the collection, and the second passes the
// document through a second filter.
//
// One common example of this is geoNear. Suppose that a geoNear plan is searching an
// annulus to find 2dsphere-indexed documents near some point (x, y) on the globe.
// After fetching documents within geo hashes that intersect this annulus, the docs are
// fetched and filtered to make sure that they really do fall into this annulus. However,
// the user might also want to find only those documents for which accommodationType==
// "restaurant". The planner will add a second fetch stage to filter by this non-geo
// predicate.
++_specificStats.docsExamined;

if (Filter::passes(member, _filter)) {
Expand Down

0 comments on commit e5800d5

Please sign in to comment.