[SERVER-23469] $match involving field generated from $unwind is pushed ahead of $unwind in pipeline Created: 01/Apr/16  Updated: 26/Apr/16  Resolved: 04/Apr/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: 3.3.5

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Benjamin Murphy
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-20506 Conditionally order $match with $unwind Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 12 (04/04/16), Query 13 (04/22/16)
Participants:

 Description   

db.pos3.aggregate([{$unwind:{path:"$likes",preserveNullAndEmptyArrays:true, includeArrayIndex:"index"}},{$match:{person:"Asya",index:0}}],{explain:true})
{
	"waitedMS" : NumberLong(0),
	"stages" : [
		{
			"$cursor" : {
				"query" : {
					"person" : "Asya",
					"index" : 0
				},
				"queryPlanner" : {
					"plannerVersion" : 1,
					"namespace" : "test.pos3",
					"indexFilterSet" : false,
					"parsedQuery" : {
						"$and" : [
							{
								"index" : {
									"$eq" : 0
								}
							},
							{
								"person" : {
									"$eq" : "Asya"
								}
							}
						]
					},
					"winningPlan" : {
						"stage" : "FETCH",
						"filter" : {
							"index" : {
								"$eq" : 0
							}
						},
						"inputStage" : {
							"stage" : "IXSCAN",
							"keyPattern" : {
								"person" : 1,
								"likes.cat" : 1,
								"likes.val" : 1
							},
							"indexName" : "person_1_likes.cat_1_likes.val_1",
							"isMultiKey" : true,
							"isUnique" : false,
							"isSparse" : false,
							"isPartial" : false,
							"indexVersion" : 1,
							"direction" : "forward",
							"indexBounds" : {
								"person" : [
									"[\"Asya\", \"Asya\"]"
								],
								"likes.cat" : [
									"[MinKey, MaxKey]"
								],
								"likes.val" : [
									"[MinKey, MaxKey]"
								]
							}
						}
					},
					"rejectedPlans" : [ ]
				}
			}
		},
		{
			"$unwind" : {
				"path" : "$likes",
				"preserveNullAndEmptyArrays" : true,
				"includeArrayIndex" : "index"
			}
		}
	],
	"ok" : 1
}

Note that "index" field comparison was moved ahead of $unwind where it might be matching a different field than generated index from $unwind, or if no such field exists, it rejects documents which should be kept.

Need to include match on generated index field in exceptions to switching match components around.



 Comments   
Comment by Githook User [ 04/Apr/16 ]

Author:

{u'username': u'benjaminmurphy', u'name': u'Benjamin Murphy', u'email': u'benjamin_murphy@me.com'}

Message: SERVER-23469 Match on unwind's indexPath is no longer optimized.
Branch: master
https://github.com/mongodb/mongo/commit/ae3ee1ceddc8af4a123090f6819d082058f3ea94

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