Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-57259

$planCacheStats fails with a confusing error message against time-series collections

    XMLWordPrintable

Details

    • Bug
    • Status: Backlog
    • Major - P3
    • Resolution: Unresolved
    • None
    • None
    • None
    • None
    • ALL

    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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: