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

A pipeline with $redact and $match can leave a new $match in the pipeline

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization
    • ALL

      For example, running

      db.foo.explain().aggregate([{$redact: "$$KEEP"}, {$match: {a: "A"}}]).stages
      

      Gives the following output:

      [
              {
                      "$cursor" : {
                              "queryPlanner" : {
                                      "namespace" : "test.foo",
                                      "indexFilterSet" : false,
                                      "parsedQuery" : {
                                              "a" : {
                                                      "$eq" : "A"
                                              }
                                      },
                                      "queryHash" : "4B53BE76",
                                      "planCacheKey" : "4B53BE76",
                                      "maxIndexedOrSolutionsReached" : false,
                                      "maxIndexedAndSolutionsReached" : false,
                                      "maxScansToExplodeReached" : false,
                                      "winningPlan" : {
                                              "stage" : "COLLSCAN",
                                              "filter" : {
                                                      "a" : {
                                                              "$eq" : "A"
                                                      }
                                              },
                                              "direction" : "forward"
                                      },
                                      "rejectedPlans" : [ ]
                              }
                      }
              },
              {
                      "$match" : {
                              "a" : {
                                      "$eq" : "A"
                              }
                      }
              },
              {
                      "$redact" : "$$KEEP"
              },
              {
                      "$match" : {
                              "a" : {
                                      "$eq" : "A"
                              }
                      }
              }
      ]
      

      where the $match after $cursor and before $redact is unexpected.

      This is happening because Pipeline::optimizePipeline() is run more than once for each pipeline, and DocumentSourceRedact::doOptimizeAt() adds a $match to the pipeline each time. See here.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            hana.pearlman@mongodb.com Hana Pearlman
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: