[SERVER-14608] {$match:{}} agg stage should be optimized out Created: 18/Jul/14  Updated: 19/Sep/15  Resolved: 12/May/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.6.3
Fix Version/s: 3.1.3

Type: Bug Priority: Major - P3
Reporter: Alan Spencer Assignee: Charlie Swanson
Resolution: Done Votes: 1
Labels: ET
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Aggregation with empty match as the first step

Sprint: Quint Iteration 3
Participants:

 Description   

Original title: Empty match at the start of the aggregation pipeline greatly impacts performance in 2.6, does not in 2.4

Aggregation below:
2.4.9 - 15-17 seconds
2.6.3 - 71-78 seconds

Removing the empty match:
2.4.9 - 15-17 seconds
2.6.3 - 15-16 seconds

db.collection.aggregate(
    { "$match" : { } },
    { "$project" : {
        "doc.field" : 1 ,
        "doc.doc1.doc2.field" : 1 ,
        "_id" : 1
    }
    },
    { "$unwind" : "$doc" } ,
    { "$unwind" : "$doc.doc1"} ,
    { "$unwind" : "$doc.doc1.doc2"} ,
    { "$group" : {
        "_id" : {
            "doc+doc1+doc2+field" : "$doc.doc1.doc2.field"
        } ,
        "count#_id"                    : { "$addToSet" : "$_id" } ,
        "count#variations+variationId" : { "$sum" : 1 }
    }
    }
);



 Comments   
Comment by Githook User [ 12/May/15 ]

Author:

{u'username': u'cswanson310', u'name': u'Charlie Swanson', u'email': u'charlie.swanson@mongodb.com'}

Message: SERVER-14608 Optimize out empty match stage in aggregation pipeline
Branch: master
https://github.com/mongodb/mongo/commit/b94f71a5dfa687aef2aa1af83e797683f9ad7476

Comment by Mathias Stearn [ 08/May/15 ]

charlie.swanson do the same as with $skip:0

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