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

Combined $match, $expr in aggregation not using indexes

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.0, 3.6.2
    • Component/s: Aggregation Framework
    • None
    • ALL
    • Hide

      Make sure the collection has an indexed property (ExternalId in this example). The query

      {{db.collection.aggregate([
      {
      "$match": {"$expr": {"$eq": ["FullProposalId","123456"]}}
      }
      ],

      {explain:true}

      )}}

      shows a COLLSCAN fetch stage
      while the simple aggregation below (that cannot be used in lookups with "lets"):
      {{db.collection.aggregate([
      {
      "$match":

      {"ExternalId":"123456"}

      }
      ],

      {explain:true}

      )

      }}
      shows an IXSCAN stage (as epxected)

      Show
      Make sure the collection has an indexed property (ExternalId in this example). The query {{db.collection.aggregate([ { "$match": {"$expr": {"$eq": ["FullProposalId","123456"] }} } ], {explain:true} )}} shows a COLLSCAN fetch stage while the simple aggregation below (that cannot be used in lookups with "lets"): {{db.collection.aggregate([ { "$match": {"ExternalId":"123456"} } ], {explain:true} ) }} shows an IXSCAN stage (as epxected)

      While using $lookup stages in aggregation pipelines using the new "Multiple Join Conditions", which requires $expr commands, the lookup uses COLLSCAN instead of indexes to fetch the destination values.

      In fact this seems to be a problem with the "$expr" command and not the $lookup phase itself. (see steps to reproduce)

            Assignee:
            Unassigned Unassigned
            Reporter:
            danielp@bompracredito.com.br Daniel Polistchuck
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: