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

[CQF] Order of fields in output documents of computed projections/addFields changes in CQF

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization

      For $addFields:

      Consider document

      { "_id" : 0, "c" : 1 }
      

      and query

      {$addFields: {d: {e: 2}, b: 3, a: {b: 4}}}
      

      For classic, the order of fields in the output document is "c" followed by the added fields in the order specified by the addFields. For CQF, the order of fields in the output document is "c" followed by "b", then "a", then "d".

      For computed projection mixed with simple inclusion:

      Consider document

      {_id: 0, a1: {b1: {c1: 1}}}
      

      and query

      {$project: {'a1.b1.c1': 1, a0: {b0: {c0: 'str'}}}}
      

      For classic, the order of fields in the output document is "a1" followed by "a0". For CQF, the order of fields in the output document is "a0" followed by "a1". Something very similar happens with only computed projections (i.e., not mixed with simple inclusion)-- CQF orders the fields alphabetically, while classic orders them according to the projection spec.

      Filed as one ticket because I think the root cause is similar.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            hana.pearlman@mongodb.com Hana Pearlman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: