[SERVER-72643] Investigate nested $unionWith regression Created: 09/Jan/23  Updated: 27/Oct/23  Resolved: 10/Mar/23

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

Type: Task Priority: Major - P3
Reporter: Mihai Andrei Assignee: Ivan Fefer
Resolution: Gone away Votes: 0
Labels: pm2697-m4
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Participants:
Story Points: 2

 Description   

The following workload has regressed: 

union_with UnionWith.UnionWithThreeCollNestedNoOverlap -12.69541889 

Here's the query:

[{$unionWith: {   coll: "Collection1",  pipeline: [{$set: {integer: "$integer"}},   {$unionWith: {coll: "Collection2", pipeline: [{$set: {integer: "$integer"}}]}}]}}] 

And the explain:

> db.coll.explain().aggregate(   [{$unionWith: {   coll: "Collection1",  pipeline: [{$set: {integer: "$integer"}},   {$unionWith: {coll: "Collection2", pipeline: [{$set: {integer: "$integer"}}]}}]}}] )
{
    "explainVersion" : "2",
    "stages" : [
        {
            "$cursor" : {
                "queryPlanner" : {
                    "namespace" : "db.coll",
                    "indexFilterSet" : false,
                    "parsedQuery" : {                    },
                    "queryHash" : "2A5DDA38",
                    "planCacheKey" : "7B89F552",
                    "maxIndexedOrSolutionsReached" : false,
                    "maxIndexedAndSolutionsReached" : false,
                    "maxScansToExplodeReached" : false,
                    "winningPlan" : {
                        "queryPlan" : {
                            "stage" : "COLLSCAN",
                            "planNodeId" : 1,
                            "filter" : {                            },
                            "direction" : "forward"
                        },
                        "slotBasedPlan" : {
                            "slots" : "$$RESULT=s4 env: { s3 = 1673294711490 (NOW), s1 = TimeZoneDatabase(Asia/Jayapura...Australia/Hobart) (timeZoneDB), s2 = Nothing (SEARCH_META) }",
                            "stages" : "[1] scan s4 s5 none none none none [] @\"8921938a-f5dc-4556-896b-1b9381e9f125\" true false "
                        }
                    },
                    "rejectedPlans" : [ ]
                }
            }
        },
        {
            "$unionWith" : {
                "coll" : "Collection1",
                "pipeline" : [
                    {
                        "$cursor" : {
                            "queryPlanner" : {
                                "namespace" : "db.Collection1",
                                "indexFilterSet" : false,
                                "parsedQuery" : {                                },
                                "queryHash" : "2A5DDA38",
                                "planCacheKey" : "6E411424",
                                "maxIndexedOrSolutionsReached" : false,
                                "maxIndexedAndSolutionsReached" : false,
                                "maxScansToExplodeReached" : false,
                                "winningPlan" : {
                                    "queryPlan" : {
                                        "stage" : "COLLSCAN",
                                        "planNodeId" : 1,
                                        "filter" : {                                        },
                                        "direction" : "forward"
                                    },
                                    "slotBasedPlan" : {
                                        "slots" : "$$RESULT=s4 env: { s3 = 1673294711490 (NOW), s1 = TimeZoneDatabase(Asia/Jayapura...Australia/Hobart) (timeZoneDB), s2 = Nothing (SEARCH_META) }",
                                        "stages" : "[1] scan s4 s5 none none none none [] @\"ebd072cd-19b2-4f47-8cdf-bcbccde6942c\" true false "
                                    }
                                },
                                "rejectedPlans" : [ ]
                            }
                        }
                    },
                    {
                        "$set" : {
                            "integer" : "$integer"
                        }
                    },
                    {
                        "$unionWith" : {
                            "coll" : "Collection2",
                            "pipeline" : [
                                {
                                    "$cursor" : {
                                        "queryPlanner" : {
                                            "namespace" : "db.Collection2",
                                            "indexFilterSet" : false,
                                            "parsedQuery" : {                                            },
                                            "queryHash" : "2A5DDA38",
                                            "planCacheKey" : "468B32E6",
                                            "maxIndexedOrSolutionsReached" : false,
                                            "maxIndexedAndSolutionsReached" : false,
                                            "maxScansToExplodeReached" : false,
                                            "winningPlan" : {
                                                "queryPlan" : {
                                                    "stage" : "COLLSCAN",
                                                    "planNodeId" : 1,
                                                    "filter" : {                                                    },
                                                    "direction" : "forward"
                                                },
                                                "slotBasedPlan" : {
                                                    "slots" : "$$RESULT=s4 env: { s1 = TimeZoneDatabase(Asia/Jayapura...Australia/Hobart) (timeZoneDB), s2 = Nothing (SEARCH_META), s3 = 1673294711490 (NOW) }",
                                                    "stages" : "[1] scan s4 s5 none none none none [] @\"7744af4c-2b82-4ec9-8ed0-07a8ea62f0ef\" true false "
                                                }
                                            },
                                            "rejectedPlans" : [ ]
                                        }
                                    }
                                },
                                {
                                    "$set" : {
                                        "integer" : "$integer"
                                    }
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ],
    "serverInfo" : {
        "host" : "ip-10-122-15-159",
        "port" : 27017,
        "version" : "6.3.0-alpha-833-g14311b5",
        "gitVersion" : "14311b5b2491c609c7d1e08d13913410c2022afc"
    },
    "serverParameters" : {
        "internalQueryFacetBufferSizeBytes" : 104857600,
        "internalQueryFacetMaxOutputDocSizeBytes" : 104857600,
        "internalLookupStageIntermediateDocumentMaxSizeBytes" : 104857600,
        "internalDocumentSourceGroupMaxMemoryBytes" : 104857600,
        "internalQueryMaxBlockingSortMemoryUsageBytes" : 104857600,
        "internalQueryProhibitBlockingMergeOnMongoS" : 0,
        "internalQueryMaxAddToSetBytes" : 104857600,
        "internalDocumentSourceSetWindowFieldsMaxMemoryBytes" : 104857600,
        "internalQueryFrameworkControl" : "tryBonsai"
    },
    "command" : {
        "aggregate" : "coll",
        "pipeline" : [
            {
                "$unionWith" : {
                    "coll" : "Collection1",
                    "pipeline" : [
                        {
                            "$set" : {
                                "integer" : "$integer"
                            }
                        },
                        {
                            "$unionWith" : {
                                "coll" : "Collection2",
                                "pipeline" : [
                                    {
                                        "$set" : {
                                            "integer" : "$integer"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ],
        "explain" : true,
        "cursor" : {        },
        "lsid" : {
            "id" : UUID("c5fa033f-f963-4fb1-b709-75c24ea632d4")
        },
        "$db" : "db"
    },
    "ok" : 1
} 

Ultimately it is 3 nested collections with some projections in the mix. 



 Comments   
Comment by Ivan Fefer [ 10/Mar/23 ]

Looked at the current perf reports: there are only improvements for this workload.
I am going to close this ticket.

Generated at Thu Feb 08 06:22:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.