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

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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:
            [DO NOT USE] Backlog - Query Optimization
            Reporter:
            Hana Pearlman
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: