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

Optimize projections in Bonsai

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Fully Compatible
    • 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
    • 35

      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

       

       

            Assignee:
            alya.berciu@mongodb.com Alya Berciu
            Reporter:
            alya.berciu@mongodb.com Alya Berciu
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: