[SERVER-19153] Conditionally push $match before $project Created: 26/Jun/15  Updated: 15/May/18  Resolved: 06/Oct/16

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

Type: New Feature Priority: Critical - P2
Reporter: Craig Wilson Assignee: David Storch
Resolution: Done Votes: 1
Labels: bi-performance, optimization
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-9547 Docs for SERVER-19153: Conditionally ... Closed
Duplicate
is duplicated by SERVER-23991 $graphLookup should optimize with $match Closed
is duplicated by SERVER-4506 aggregation: optimize by pushing mat... Closed
Related
related to SERVER-23991 $graphLookup should optimize with $match Closed
is related to SERVER-142 Read-only views over collection data. Closed
is related to SERVER-26442 Push $sort before $project and $addFi... Open
is related to SERVER-26598 conditionally push $match before $add... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2016-09-19, Query 2016-10-10
Participants:

 Description   

I was looking at the optimizing aggregation pipelines docs page and didn't see this one listed.

This is only possible if the subsequent $match doesn't use any computed fields, but there could be a large win with regards to index usage if you could move the $match prior to a $project.

For example:

{ $project: { a: 1, b: 1, newField: { $add: ["$a", "$b"] } } },
{ $match: { a : { $gt: 10 } }

is the same as

{ $match: { a : { $gt: 10 } },
{ $project: { a: 1, b: 1, newField: { $add: ["$a", "$b"] } } }

because the $match is only using fields that exist in the original document.



 Comments   
Comment by Githook User [ 06/Oct/16 ]

Author:

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

Message: SERVER-19153 push $match as far forward as possible
Branch: master
https://github.com/mongodb/mongo/commit/4976eb401b3f16482fb35287ea60d7e8b33fe76d

Comment by David Storch [ 03/Oct/16 ]

I've limited the scope of this ticket to be specifically about swapping $match with $project. Swapping $sort and $project is now a separate work item tracked by SERVER-26442.

Comment by Charlie Swanson [ 26/Jul/16 ]

Bumping to 3.3 Required to make views more usable.

Comment by Charlie Swanson [ 21/Jan/16 ]

Yep, this looks like a duplicate. Closing as such.

Comment by Asya Kamsky [ 20/Jan/16 ]

Part of SERVER-4506?

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