[SERVER-20506] Conditionally order $match with $unwind Created: 18/Sep/15  Updated: 05/Dec/16  Resolved: 30/Mar/16

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Performance
Affects Version/s: None
Fix Version/s: 3.3.4

Type: Improvement Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Benjamin Murphy
Resolution: Done Votes: 0
Labels: bi-performance, optimization
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-22833 MatchExpression::toBSON does not nece... Closed
Documented
is documented by DOCS-9499 Docs for SERVER-20506: Conditionally ... Closed
Duplicate
is duplicated by SERVER-4506 aggregation: optimize by pushing mat... Closed
Related
related to SERVER-23469 $match involving field generated from... Closed
related to SERVER-4506 aggregation: optimize by pushing mat... Closed
is related to SERVER-23444 Pessimizing moves break compile on cl... Closed
is related to SERVER-4506 aggregation: optimize by pushing mat... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 10 (02/22/16), Query 11 (03/14/16), Query 12 (04/04/16)
Participants:

 Description   

The subset of a $match following an $unwind that does not filter on the unwound field can be moved up in the pipeline.

For example:

[
  {'$unwind' : "$x"}, 
  {'$match' : {_id : 1, x : {'$gt': 3}  } }
]

is equivalent to:

[ 
   {'$match' : {_id : 1} }, 
   {'$unwind' : "$x"}, 
   {'$match' : {x : {'$gt': 3}} }
]



 Comments   
Comment by Benjamin Murphy [ 30/Mar/16 ]

This ticket introduces a new aggregation optimization, allowing a $match stage following a $unwind to split into two pieces: One that is dependent upon the path being unwound, and one that is not. The independent $match is put before the $unwind in the pipeline, and the dependent after.

Comment by Githook User [ 30/Mar/16 ]

Author:

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

Message: SERVER-20506 Conditionally order match and unwind.
Branch: master
https://github.com/mongodb/mongo/commit/2b56c5ce4527403329bc60ee406a0f1a7de3f10a

Comment by Asya Kamsky [ 20/Jan/16 ]

Part of SERVER-4506?

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