Constants used in uncorrelated match in subpipelines stored in runtime environment can be lost

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Issue occurs only when running with featureFlagSbeFull=true

      Using a modified Q10

      db.orders.explain().aggregate(
      [
            {
              $match:
                {
                  $and:
                    [
                      { $expr: { $gte: ["$o_orderdate", new Date("1993-10-01")] } },
                      {
                        $expr:
                          {
                            $lt:
                              [
                                "$o_orderdate",
                                {
                                  $dateAdd:
                                    {
                                      startDate: new Date("1993-10-01"),
                                      unit: "month",
                                      amount: 3,
                                    },
                                },
                              ],
                          },
                      },
                    ],
                },
            },
            {
              $lookup:
                {
                  from: "lineitem",
                  localField: "o_orderkey",
                  foreignField: "l_orderkey",
                  as: "lineitem",
                  pipeline: [{ $match: { l_returnflag: "R" } }],
                },
            },
            { $unwind: "$lineitem" },
            {
              $lookup:
                {
                  from: "customer",
                  localField: "o_custkey",
                  foreignField: "c_custkey",
                  as: "customer",
                },
            },
            { $unwind: "$customer" },
            {
              $lookup:
                {
                  from: "nation",
                  localField: "customer.c_nationkey",
                  foreignField: "n_nationkey",
                  as: "nation",
                },
            },
            { $unwind: "$nation" },
            {
              $group:
                {
                  _id:
                    {
                      c_custkey: "$customer.c_custkey",
                      c_name: "$customer.c_name",
                      c_acctbal: "$customer.c_acctbal",
                      n_name: "$nation.n_name",
                      c_address: "$customer.c_address",
                      c_phone: "$customer.c_phone",
                      c_comment: "$customer.c_comment",
                    },
                  revenue:
                    {
                      $sum:
                        {
                          $multiply:
                            [
                              "$lineitem.l_extendedprice",
                              { $subtract: [1, "$lineitem.l_discount"] },
                            ],
                        },
                    },
                },
            },
            {
              $project:
                {
                  _id: 0,
                  c_custkey: "$_id.c_custkey",
                  c_name: "$_id.c_name",
                  c_acctbal: "$_id.c_acctbal",
                  n_name: "$_id.n_name",
                  c_address: "$_id.c_address",
                  c_phone: "$_id.c_phone",
                  c_comment: "$_id.c_comment",
                  revenue: 1,
                },
            },
            { $sort: { revenue: -1 } },
            { $limit: 20 },
          ])

      the 

      { $match: { l_returnflag: "R" } }

      condition is rendered as 

      [6] filter {traverseF(getField(s19, "l_returnflag"), lambda(l4.0) { ((move(l4.0) == s22) ?: false) }, false)}

      but the s22 slot in the runtime environment is assigned to a Nothing value, instead of the literal "R"

            Assignee:
            Alberto Massari
            Reporter:
            Alberto Massari
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: