[SERVER-56506] Fix the "relevantSlots" logic in sbe_stage_builder_projection.cpp Created: 30/Apr/21  Updated: 29/Oct/23  Resolved: 12/May/21

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

Type: Bug Priority: Major - P3
Reporter: Drew Paroski Assignee: Drew Paroski
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-52799 Make sbe the default execution engine... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

> db.coll.insert({a: 1});
> db.coll.aggregate([\{"$project": {"a.x": "$a.x", "a.b.x": "$a.x"}}]);

Sprint: Query Execution 2021-05-17
Participants:

 Description   

I was working on something totally unrelated and ran "aggregation_multiversion_fuzzer" with SBE enabled, and I found an interesting failure:

https://spruce.mongodb.com/task/mongodb_mongo_master_enterprise_rhel_80_64_bit_dynamic_all_feature_flags_required_aggregation_multiversion_fuzzer_4_enterprise_rhel_80_64_bit_dynamic_all_feature_flags_required_patch_d6f45f76d79d7905fba6ee90a6e805b3cd9a1370_608afc860ae6062333543496_21_04_29_18_36_47/tests?execution=0&sortBy=STATUS&sortDir=ASC

I was able to boil it down to the following repro:

> db.coll.insert({a: 1});
> db.coll.aggregate([{"$project": {"a.x": "$a.x", "a.b.x": "$a.x"}}]);

Running these commands with SBE enabled will produce the following error message:

uncaught exception: Error: command failed: { "ok" : 0, "errmsg" : "undefined slot accessor:6", "code" : 4946301, "codeName" : "Location4946301"} with original command request: { "aggregate" : "coll", "pipeline" : [ { "$project" : { "a.x" : "$a.x", "a.b.x" : "$a.x" } } ], "cursor" : { }, "lsid" : { "id" : UUID("fd211cab-715c-41fa-827c-c0ae006ca0a8") }} on connection: connection to 127.0.0.1:27017 : aggregate failed

Running these commands with SBE disabled produces no error.

I attached gdb and I managed to print out the generated SBE plan that is causing theĀ "undefined slot accessor:6" error (see below). It appears that "s6" is being read from in a context where it is not defined.

The goal of this task is to fix this bug.

== SBE plan of the aggregate() command that fails ==

[2] traverse s22 s21 s3 {} {}
from
  [1] scan s3 s4 none none none none [] @"7a47a3f3-af02-40d4-960c-caaa4a5da425" true false
in
  [2] mkbson s21 s3 [_id] keep [a = s20] true false
  [2] traverse s20 s19 s5 {} {}
  from
    [2] project [s5 = getField (s3, "a")]
    [2] limit 1
    [2] coscan
  in
    [2] mkbson s19 s5 [] keep [x = s10, b = s18] true false
    [2] project [s10 = s7]
    [2] traverse s18 s17 s11 {} {}
    from
      [2] project [s11 = getField (s5, "b")]
      [2] traverse s7 s7 s6 {} {}
      from
        [2] project [s6 = getField (s3, "a")]
        [2] limit 1
        [2] coscan
      in
        [2] project [s7 = s9]
        [2] traverse s9 s9 s8 {} {}
        from
          [2] project [s8 = getField (s6, "x")]
          [2] limit 1
          [2] coscan
        in
          [2] project [s9 = s8]
          [2] limit 1
          [2] coscan
    in
      [2] mkbson s17 s11 [] keep [x = s16] true false
      [2] project [s16 = s13]
      [2] traverse s13 s13 s12 [s6, s7] {} {}
      from
        [2] project [s12 = getField (s3, "a")]
        [2] limit 1
        [2] coscan
      in
        [2] project [s13 = s15]
        [2] traverse s15 s15 s14 {} {}
        from
          [2] project [s14 = getField (s12, "x")]
          [2] limit 1
          [2] coscan
        in
          [2] project [s15 = s14]
          [2] limit 1
          [2] coscan



 Comments   
Comment by Githook User [ 12/May/21 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-56506 Fix the "relevantSlots" logic in sbe_stage_builder_projection.cpp
Branch: master
https://github.com/mongodb/mongo/commit/a34847b4091f1c86a94df78acee403a973dc9329

Generated at Thu Feb 08 05:39:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.