[SERVER-38063] executionStats or allPlansExecution level explain of an aggregate with a $out does writes Created: 09/Nov/18  Updated: 29/Oct/23  Resolved: 07/Dec/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Diagnostics
Affects Version/s: 4.0.4, 4.1.5
Fix Version/s: 4.1.7

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

Issue Links:
Depends
Documented
is documented by DOCS-12249 Docs for SERVER-38063: executionStats... Closed
Related
related to SERVER-38064 Pipeline::dispose() should not check ... Closed
is related to SERVER-29421 Aggregation executionStats or allPlan... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:
Linked BF Score: 15

 Description   

We allow explaining write operations such as the update and delete commands. However, these operations are never supposed to perform writes. An explain of an $out aggregation stage should behave similarly. However, an "executionStats" or "allPlansExecution" verbosity explain of an $out will actually persist the results to the target collection:

> db.inputColl.drop()
false
> db.inputColl.insert({_id: 1})
WriteResult({ "nInserted" : 1 })
> db.inputColl.explain("executionStats").aggregate([{$out: "outputColl"}])
{
	"stages" : [
		{
			"$cursor" : {
				"query" : {
 
				},
				"queryPlanner" : {
					"plannerVersion" : 1,
					"namespace" : "test.inputColl",
					"indexFilterSet" : false,
					"parsedQuery" : {
 
					},
					"queryHash" : "8B3D4AB8",
					"planCacheKey" : "8B3D4AB8",
					"winningPlan" : {
						"stage" : "COLLSCAN",
						"direction" : "forward"
					},
					"rejectedPlans" : [ ]
				},
				"executionStats" : {
					"executionSuccess" : true,
					"nReturned" : 1,
					"executionTimeMillis" : 59,
					"totalKeysExamined" : 0,
					"totalDocsExamined" : 1,
					"executionStages" : {
						"stage" : "COLLSCAN",
						"nReturned" : 1,
						"executionTimeMillisEstimate" : 0,
						"works" : 3,
						"advanced" : 1,
						"needTime" : 1,
						"needYield" : 0,
						"saveState" : 2,
						"restoreState" : 2,
						"isEOF" : 1,
						"direction" : "forward",
						"docsExamined" : 1
					}
				}
			}
		},
		{
			"$out" : {
				"to" : "outputColl",
				"db" : "test",
				"mode" : "replaceCollection",
				"uniqueKey" : {
					"_id" : 1
				}
			}
		}
	],
	"ok" : 1
}
> db.outputColl.find()
{ "_id" : 1 }

This behavior was most likely introduced by the fixes to executionStats agg explain under SERVER-29421.

Instead, we should probably raise an error if a user attempts to perform this operation with an error message such as "$out cannot be explain with 'executionStats' level verbosity or higher". Users who wish to explain an $out operation with execution stats can simply drop the $out stage from the tail of their pipeline.



 Comments   
Comment by Githook User [ 07/Dec/18 ]

Author:

{'name': 'David Storch', 'email': 'david.storch@10gen.com', 'username': 'dstorch'}

Message: SERVER-38063 Fail cleanly on execution-level explain of $out pipeline.
Branch: master
https://github.com/mongodb/mongo/commit/7000ad6f39fe8a6cc82935bb5a81a0a278b98661

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