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

{$match:{}} agg stage should be optimized out

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.3
    • Affects Version/s: 2.6.3
    • Component/s: Aggregation Framework
    • Labels:
    • Fully Compatible
    • ALL
    • Hide

      Aggregation with empty match as the first step

      Show
      Aggregation with empty match as the first step
    • Quint Iteration 3

      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 }
          }
          }
      );
      

            Assignee:
            charlie.swanson@mongodb.com Charlie Swanson
            Reporter:
            alan.spencer Alan Spencer
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: