[SERVER-55458] A pipeline with $redact and $match can leave a new $match in the pipeline Created: 23/Mar/21  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Hana Pearlman Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

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.


Generated at Thu Feb 08 05:36:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.