[SERVER-23064] COUNT_SCAN query execution stage does not report index bounds in execution stats output for explain Created: 10/Mar/16  Updated: 05/Jul/16  Resolved: 10/Jun/16

Status: Closed
Project: Core Server
Component/s: Diagnostics, Querying
Affects Version/s: None
Fix Version/s: 3.3.9

Type: Improvement Priority: Major - P3
Reporter: J Rassi Assignee: David Hatch
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Query 16 (06/24/16)
Participants:

 Description   

The execution stats output for explain of a query plan containing the COUNT_SCAN execution stage is missing index bounds information. The other index access stages correctly report their associated index bounds.

> db.foo.drop()
true
> db.foo.ensureIndex({a:1})
{
	"createdCollectionAutomatically" : true,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.foo.explain('executionStats').find({a:1})  // Index bounds correctly reported.
...
				"stage" : "IXSCAN",
				"nReturned" : 0,
				"executionTimeMillisEstimate" : 0,
				"works" : 1,
				"advanced" : 0,
				"needTime" : 0,
				"needYield" : 0,
				"saveState" : 0,
				"restoreState" : 0,
				"isEOF" : 1,
				"invalidates" : 0,
				"keyPattern" : {
					"a" : 1
				},
				"indexName" : "a_1",
				"isMultiKey" : false,
				"isUnique" : false,
				"isSparse" : false,
				"isPartial" : false,
				"indexVersion" : 1,
				"direction" : "forward",
				"indexBounds" : {
					"a" : [
						"[1.0, 1.0]"
					]
				},
...
> db.foo.explain('executionStats').distinct('a') // Index bounds correctly reported.
...
				"stage" : "DISTINCT_SCAN",
				"nReturned" : 0,
				"executionTimeMillisEstimate" : 0,
				"works" : 1,
				"advanced" : 0,
				"needTime" : 0,
				"needYield" : 0,
				"saveState" : 0,
				"restoreState" : 0,
				"isEOF" : 1,
				"invalidates" : 0,
				"keyPattern" : {
					"a" : 1
				},
				"indexName" : "a_1",
				"isMultiKey" : false,
				"isUnique" : false,
				"isSparse" : false,
				"isPartial" : false,
				"indexVersion" : 1,
				"direction" : "forward",
				"indexBounds" : {
					"a" : [
						"[MinKey, MaxKey]"
					]
				},
...
> db.foo.explain('executionStats').count({a:1}) // Index bounds not reported.
...
			"inputStage" : {
				"stage" : "COUNT_SCAN",
				"nReturned" : 0,
				"executionTimeMillisEstimate" : 0,
				"works" : 1,
				"advanced" : 0,
				"needTime" : 0,
				"needYield" : 0,
				"saveState" : 0,
				"restoreState" : 0,
				"isEOF" : 1,
				"invalidates" : 0,
				"keysExamined" : 1,
				"keyPattern" : {
					"a" : 1
				},
				"indexName" : "a_1",
				"isMultiKey" : false,
				"isUnique" : false,
				"isSparse" : false,
				"isPartial" : false,
				"indexVersion" : 1
			}
...



 Comments   
Comment by Githook User [ 10/Jun/16 ]

Author:

{u'username': u'dhatch', u'name': u'David Hatch', u'email': u'david.hatch@mongodb.com'}

Message: SERVER-23064 COUNT_SCAN query execution stage does not report index bounds in execution stats output for explain
Branch: master
https://github.com/mongodb/mongo/commit/f3f756132c74c1b44696d30faf6ef806fc7de860

Comment by J Rassi [ 03/Jun/16 ]

Actually, I'm not sure if startKey and endKey have empty field names. If they do, we'll have to translate those objects to have the appropriate field names from keyPattern in order to display them properly in the shell (the shell won't display elements that have duplicate field names, which would be the case if they're all empty).

Comment by J Rassi [ 03/Jun/16 ]

Dave's proposal sounds good to me.

Comment by David Storch [ 03/Jun/16 ]

david.hatch, I think it should just report startKey, startKeyInclusive, endKey, and endKeyInclusive.

Comment by David Hatch [ 03/Jun/16 ]

j.rassi, is the intention here to add the CountScanParams startKey and endKey as the index bounds in the explain output? I noticed that IXSCAN stages have an IndexBounds associated with them, while CountScan just uses a range. Furthermore, IndexBounds produce explain output, so one option would be to switch CountScan to using an IndexBounds, although it would only support simple contiguous bounds so that we can avoid using IndexBoundsChecker. Alternatively, CountScan could produce the same output as IndexBounds::toBSON without switching to utilize it.

Generated at Thu Feb 08 04:02:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.