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

$match involving field generated from $unwind is pushed ahead of $unwind in pipeline

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.3.5
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Sprint:
      Query 12 (04/04/16), Query 13 (04/22/16)

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              benjamin.murphy Benjamin Murphy
              Reporter:
              asya Asya Kamsky
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: