[SERVER-79367] Optimize projections in Bonsai Created: 26/Jul/23  Updated: 28/Nov/23  Resolved: 20/Nov/23

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

Type: Improvement Priority: Major - P3
Reporter: Alya Berciu Assignee: Alya Berciu
Resolution: Fixed Votes: 0
Labels: M2, auto-reverted
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-80579 Microbenchmarks - investigate regress... Backlog
is depended on by SERVER-81851 Constant-fold makeBsonObj Backlog
is depended on by SERVER-80578 Microbenchmarks - investigate regress... Closed
is depended on by SERVER-81888 Path fusion rewrite to mark the root ... Backlog
is depended on by SERVER-81865 Use mkbson instead of project for sim... Closed
Fix
fixes SERVER-80577 Microbenchmarks - investigate regress... Closed
Problem/Incident
Related
related to SERVER-80580 Microbenchmarks - investigate regress... Closed
is related to SERVER-80240 Additions to Bonsai const folding Backlog
Backwards Compatibility: Fully Compatible
Sprint: QO 2023-09-04, QO 2023-09-18, QO 2023-10-02, QO 2023-10-16, QO 2023-10-30, QO 2023-11-13, QO 2023-11-27
Participants:
Linked BF Score: 35

 Description   

Plans which include projections in Bonsai can produce additional SBE code that may be negatively impacting the performance of projection microbenchmarks. For example, the SBE plan generated by the stage builders for the simple query db.a.find({}, {a: 1, b: 1, c: 1}) is:

$$RESULT=s6 env: { s3 = 1690384319772 (NOW), s1 = TimeZoneDatabase(Asia/Phnom_Penh...Africa/Bamako) (timeZoneDB), s2 = Nothing (SEARCH_META) }
 
[2] mkbson s6 s4 [_id, a, b, c] keep [] true false
[1] scan s4 s5 none none none none none none lowPriority [] @"01f02723-1a68-44b2-9267-469b17d04b76" true false

While the SBE plan generated by Bonsai is much more complicated:

 

 

 $$RESULT=s6 env: { s1 = Nothing (shardFilterer) }
 
 [1] project [s6 =
    let [
        l101.0 =
            let [
                l102.0 =
                    let [
                        l103.0 =
                            if (exists(s2) || isObject({}))
                            then setField({}, "_id", s2)
                            else {}
                    ]
                    in
                        if (exists(s3) || isObject(l103.0))
                        then setField(move(l103.0), "a", s3)
                        else move(l103.0)
            ]
            in
                if (exists(s4) || isObject(l102.0))
                then setField(move(l102.0), "b", s4)
                else move(l102.0)
    ]
    in
        if (exists(s5) || isObject(l101.0))
        then setField(move(l101.0), "c", s5)
        else move(l101.0)
]
[0] scan none none none none none none none none lowPriority [s2 = _id, s3 = a, s4 = b, s5 = c] @"01f02723-1a68-44b2-9267-469b17d04b76" true false

 

 



 Comments   
Comment by Githook User [ 20/Nov/23 ]

Author:

{'name': 'Alya Berciu', 'email': 'alya.berciu@mongodb.com', 'username': 'alyacb'}

Message: SERVER-79367 Implement path lowering to makeBsonObj/MakeObjSpec

This reverts commit 43c42019fee86ebf3d85a2e7f3873686f6e546d2.
Branch: master
https://github.com/mongodb/mongo/commit/6a5c4c776bbe6c1a3e01ef6a3b6466c27c8fd935

Comment by Githook User [ 18/Nov/23 ]

Author:

{'name': 'auto-revert-processor', 'email': 'dev-prod-dag@mongodb.com', 'username': ''}

Message: Revert "SERVER-79367 Implement path lowering to makeBsonObj/MakeObjSpec"

This reverts commit fcb7d5e9d4d256d1c33f69b406bf75731a83a192.
Branch: master
https://github.com/mongodb/mongo/commit/43c42019fee86ebf3d85a2e7f3873686f6e546d2

Comment by Githook User [ 17/Nov/23 ]

Author:

{'name': 'Alya Carina Berciu', 'email': 'alya.berciu@mongodb.com', 'username': 'alyacb'}

Message: SERVER-79367 Implement path lowering to makeBsonObj/MakeObjSpec
Branch: master
https://github.com/mongodb/mongo/commit/fcb7d5e9d4d256d1c33f69b406bf75731a83a192

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