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

explain output for sharded count command is incorrect

    • Query Execution
    • ALL

      When run against a sharded collection with multiple shards, it looks like the explain implementation will simply forward the count command to each shard, which would be incorrect and is not what the regular, non-explain implementation does. More specifically, if there is a skip specified, that should not be forwarded to the shards.

      This can be observed by running the test jstests/core/explain_count.js against a cluster with multiple shards - although without modification the test will fail earlier because it doesn't correctly add the 'nSkipped' totals from each shard. Once that issue is resolved, this assertion fails, because each shard will apply the skip of 3 in the explained version, resulting in the following explain output, implying there were only 4 in the resulting count:

      [js_test:explain_count] 2018-01-04T23:56:43.232+0000 {
      [js_test:explain_count] 2018-01-04T23:56:43.232+0000 	"queryPlanner" : {
      [js_test:explain_count] 2018-01-04T23:56:43.232+0000 		"mongosPlannerVersion" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.232+0000 		"winningPlan" : {
      [js_test:explain_count] 2018-01-04T23:56:43.232+0000 			"stage" : "SHARD_MERGE",
      [js_test:explain_count] 2018-01-04T23:56:43.232+0000 			"shards" : [
      [js_test:explain_count] 2018-01-04T23:56:43.232+0000 				{
      [js_test:explain_count] 2018-01-04T23:56:43.233+0000 					"shardName" : "shard0000",
      [js_test:explain_count] 2018-01-04T23:56:43.233+0000 					"connectionString" : "localhost:20503",
      [js_test:explain_count] 2018-01-04T23:56:43.233+0000 					"serverInfo" : {
      [js_test:explain_count] 2018-01-04T23:56:43.233+0000 						"host" : "ip-10-218-215-76",
      [js_test:explain_count] 2018-01-04T23:56:43.233+0000 						"port" : 20503,
      [js_test:explain_count] 2018-01-04T23:56:43.233+0000 						"version" : "3.7.0-405-g534b1d0c5a-patch-5a4eb2bfe3c33103b7004eb0",
      [js_test:explain_count] 2018-01-04T23:56:43.233+0000 						"gitVersion" : "534b1d0c5abc8f62d7e3961081f54fd965480ddc"
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 					},
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 					"plannerVersion" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 					"namespace" : "test.jstests_explain_count",
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 					"indexFilterSet" : false,
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 					"winningPlan" : {
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 						"stage" : "COUNT"
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 					},
      [js_test:explain_count] 2018-01-04T23:56:43.234+0000 					"rejectedPlans" : [ ]
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 				},
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 				{
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 					"shardName" : "shard0001",
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 					"connectionString" : "localhost:20504",
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 					"serverInfo" : {
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 						"host" : "ip-10-218-215-76",
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 						"port" : 20504,
      [js_test:explain_count] 2018-01-04T23:56:43.235+0000 						"version" : "3.7.0-405-g534b1d0c5a-patch-5a4eb2bfe3c33103b7004eb0",
      [js_test:explain_count] 2018-01-04T23:56:43.236+0000 						"gitVersion" : "534b1d0c5abc8f62d7e3961081f54fd965480ddc"
      [js_test:explain_count] 2018-01-04T23:56:43.236+0000 					},
      [js_test:explain_count] 2018-01-04T23:56:43.236+0000 					"plannerVersion" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.236+0000 					"namespace" : "test.jstests_explain_count",
      [js_test:explain_count] 2018-01-04T23:56:43.236+0000 					"indexFilterSet" : false,
      [js_test:explain_count] 2018-01-04T23:56:43.237+0000 					"winningPlan" : {
      [js_test:explain_count] 2018-01-04T23:56:43.237+0000 						"stage" : "COUNT"
      [js_test:explain_count] 2018-01-04T23:56:43.237+0000 					},
      [js_test:explain_count] 2018-01-04T23:56:43.237+0000 					"rejectedPlans" : [ ]
      [js_test:explain_count] 2018-01-04T23:56:43.237+0000 				}
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 			]
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 		}
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 	},
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 	"executionStats" : {
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 		"nReturned" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 		"executionTimeMillis" : 2,
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 		"totalKeysExamined" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 		"totalDocsExamined" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.238+0000 		"executionStages" : {
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 			"stage" : "SHARD_MERGE",
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 			"nReturned" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 			"executionTimeMillis" : 2,
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 			"totalKeysExamined" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 			"totalDocsExamined" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 			"totalChildMillis" : NumberLong(0),
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 			"shards" : [
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 				{
      [js_test:explain_count] 2018-01-04T23:56:43.239+0000 					"shardName" : "shard0000",
      [js_test:explain_count] 2018-01-04T23:56:43.240+0000 					"executionSuccess" : true,
      [js_test:explain_count] 2018-01-04T23:56:43.240+0000 					"executionStages" : {
      [js_test:explain_count] 2018-01-04T23:56:43.240+0000 						"stage" : "COUNT",
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"nReturned" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"executionTimeMillisEstimate" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"works" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"advanced" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"needTime" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"needYield" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"saveState" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.241+0000 						"restoreState" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.242+0000 						"isEOF" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.242+0000 						"invalidates" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.242+0000 						"nCounted" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.242+0000 						"nSkipped" : 0
      [js_test:explain_count] 2018-01-04T23:56:43.242+0000 					}
      [js_test:explain_count] 2018-01-04T23:56:43.243+0000 				},
      [js_test:explain_count] 2018-01-04T23:56:43.243+0000 				{
      [js_test:explain_count] 2018-01-04T23:56:43.243+0000 					"shardName" : "shard0001",
      [js_test:explain_count] 2018-01-04T23:56:43.243+0000 					"executionSuccess" : true,
      [js_test:explain_count] 2018-01-04T23:56:43.243+0000 					"executionStages" : {
      [js_test:explain_count] 2018-01-04T23:56:43.243+0000 						"stage" : "COUNT",
      [js_test:explain_count] 2018-01-04T23:56:43.244+0000 						"nReturned" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.244+0000 						"executionTimeMillisEstimate" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.244+0000 						"works" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.244+0000 						"advanced" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.244+0000 						"needTime" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.244+0000 						"needYield" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 						"saveState" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 						"restoreState" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 						"isEOF" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 						"invalidates" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 						"nCounted" : 0,
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 						"nSkipped" : 0
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 					}
      [js_test:explain_count] 2018-01-04T23:56:43.245+0000 				}
      [js_test:explain_count] 2018-01-04T23:56:43.246+0000 			]
      [js_test:explain_count] 2018-01-04T23:56:43.246+0000 		}
      [js_test:explain_count] 2018-01-04T23:56:43.246+0000 	},
      [js_test:explain_count] 2018-01-04T23:56:43.246+0000 	"ok" : 1,
      [js_test:explain_count] 2018-01-04T23:56:43.246+0000 	"$clusterTime" : {
      [js_test:explain_count] 2018-01-04T23:56:43.246+0000 		"clusterTime" : Timestamp(1515110203, 12),
      [js_test:explain_count] 2018-01-04T23:56:43.247+0000 		"signature" : {
      [js_test:explain_count] 2018-01-04T23:56:43.247+0000 			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      [js_test:explain_count] 2018-01-04T23:56:43.247+0000 			"keyId" : NumberLong(0)
      [js_test:explain_count] 2018-01-04T23:56:43.247+0000 		}
      [js_test:explain_count] 2018-01-04T23:56:43.247+0000 	},
      [js_test:explain_count] 2018-01-04T23:56:43.247+0000 	"operationTime" : Timestamp(1515110203, 12)
      [js_test:explain_count] 2018-01-04T23:56:43.247+0000 }
      

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: