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

Use internal names during stage reordering to prevent ambiguity

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization
    • ALL
    • QO 2022-10-31, QO 2022-11-14, QO 2022-11-28, QO 2022-12-12, QO 2022-12-26, QO 2023-01-09

      The cause of the linked BF is that the given query is ambiguous - it asks for a field from $obj and then modifies obj in the same $project:

      db.coll.aggregate( [{$project: {"time": "$obj.date", "obj": {$unsetField: {field: "text", input: {k: "text2", v: "$tag.assistant"}}}}}, {$sort: {_id: 1}}, {$limit: 20}] )
      

      As a result, without optimization, $obj.date is missing; but with optimization, $addFields is added before $_internalUnpackBucket as part of stage reordering, resulting in $obj.date returning a value.

      After discussing with Chris and Katya, both confirmed that we should make the output match the output of the non-optimized case. Alberto's suggestion for achieving this was that the optimization that moves $addFields before $internalUnpackBucket should be using an internal name rather than "obj", like:

      "$addFields:" (
              "kInternalName1" : {
      ...
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            jennifer.peshansky@mongodb.com Jennifer Peshansky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: