[SERVER-47961] Explain the UPDATE stage Created: 05/May/20  Updated: 06/Dec/22

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

Type: Improvement Priority: Major - P3
Reporter: David Percy Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Participants:

 Description   

When you explain an update command, it only shows how the query part is executed; it doesn't show anything about the update part.

> db.c.explain().findAndModify({_id: 123}, [{$set:{x:45}}], {upsert:true})
{
	"queryPlanner" : {
		"plannerVersion" : 1,
		"namespace" : "test.c",
		"indexFilterSet" : false,
		"winningPlan" : {
			"stage" : "UPDATE",
			"inputStage" : {
				"stage" : "IDHACK"
			}
		},
		"rejectedPlans" : [ ]
	},
	"serverInfo" : {
		"host" : "dpercy-desktop",
		"port" : 27017,
		"version" : "4.5.0-970-g847dfa3",
		"gitVersion" : "847dfa31a717d9e57028de7cd39e45dc15d3b405"
	},
	"ok" : 1
}

I think the UPDATE stage should include information like:

  • how the [{$set: {x: 45}}] pipeline is represented
  • whether it's a multi-update
  • whether it's an upsert
  • which version of the updated document will be returned (new, old, or none)

Also, if possible:

  • which indexes will need updating

This last item could be helpful for deciding whether you have too many indexes. If an update is slow, you .explain() it and see all the indexes that are slowing it down.



 Comments   
Comment by Bernard Gorman [ 26/May/21 ]

david.percy: most of this information is available if you run the explain with "executionStats" verbosity, where the UPDATE stage (or DELETE stage if this is a fAM with remove:true) will tell you how many documents we would modify, whether we would upsert a new document, whether we would delete a document, whether we would return a document, etc.

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