[SERVER-57259] $planCacheStats fails with a confusing error message against time-series collections Created: 27/May/21  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

Example:

MongoDB Enterprise > db.t.drop()
true
MongoDB Enterprise > db.createCollection("t", {timeseries: {timeField: "tf"}})
{ "ok" : 1 }
MongoDB Enterprise > db.t.aggregate([{$planCacheStats: {}}])
uncaught exception: Error: command failed: {
	"ok" : 0,
	"errmsg" : "$planCacheStats is only valid as the first stage in a pipeline.",
	"code" : 40602,
	"codeName" : "Location40602"
} with original command request: {
	"aggregate" : "t",
	"pipeline" : [
		{
			"$planCacheStats" : {
 
			}
		}
	],
	"cursor" : {
 
	},
	"lsid" : {
		"id" : UUID("4a3afe13-04c7-4e64-847e-9013a6449132")
	}
} on connection: connection to 127.0.0.1:27017 : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:719:17
assert.commandWorked@src/mongo/shell/assert.js:811:16
DB.prototype._runAggregate@src/mongo/shell/db.js:276:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1058:12
@(shell):1:1

The error message states that $planCacheStats is not the first stage in the pipeline. This may be confusing to the user, since from the user's perspective it is indeed first in the pipeline. The reason for this error is that the query goes through the view resolution path, which inserts an $_internalUnpackBucket stage at the beginning of the pipeline. Only after view resolution is the constraint about $planCacheStats being first checked.

We should either improve the error message, or better, make $planCacheStats actually work against time-series collections. Note that we have already implemented a special case to allow $indexStats to work; this logic should be extended to $planCacheStats.



 Comments   
Comment by Michael Gargiulo [ 04/Jun/21 ]

charlie.swanson this isn't a huge priority from my perspective at this point as $planCacheStats can be directly run against the buckets collection and likely makes more sense since I can envision the primary user of this would be the support team 

Comment by Charlie Swanson [ 03/Jun/21 ]

michael.gargiulo and kateryna.kamenieva we're putting this on the backlog for now, but happy to do this if you think it's an important thing to do soon.

Generated at Thu Feb 08 05:41:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.