ExportXMLWordPrintableJSON

    • Query Optimization
    • Fully Compatible
    • ALL
    • Hide
      
      /**
       * JOO tassert 5182300 / 4822878 "Unsupported (match) expression in SBE stage builder": a $match
       * that classic executes fine but SBE cannot lower, placed before the first $lookup or inside a
       * $lookup sub-pipeline, is pushed into a join node's CanonicalQuery and lowered to SBE anyway.
       *
       * createCQForJoinPipeline() marks every join-node CanonicalQuery SBE-compatible unconditionally;
       * the eligibility checks only reject $text. Without join optimization these pipelines run in the
       * classic engine and succeed.
       */
      const conn = MongoRunner.runMongod({
          setParameter: {
              internalEnableJoinOptimization: true,
              featureFlagPathArrayness: true,
              featureFlagCostBasedRanker: true,
          },
      });
      const db = conn.getDB("test");
      try {
          assert.commandWorked(db.a.insertMany([{_id: 1, x: 1}, {_id: 2, x: 2}]));
          assert.commandWorked(db.b.insertMany([{_id: 1, y: 1}, {_id: 2, y: 2}]));
          assert.commandWorked(db.a.createIndex({x: 1}));
          assert.commandWorked(db.b.createIndex({y: 1}));
      
          const lookup = {$lookup: {from: "b", localField: "x", foreignField: "y", as: "b"}};
          const pipelines = {
              // $getField in a $match $expr before the $lookup (5182300).
              getField: [{$match: {$expr: {$eq: [{$getField: {field: "x", input: "$$ROOT"}}, 1]}}}, lookup, {$unwind: "$b"}],
              // $jsonSchema before the $lookup (4822878).
              jsonSchema: [{$match: {$jsonSchema: {properties: {x: {bsonType: "int"}}}}}, lookup, {$unwind: "$b"}],
              // $function in the $lookup sub-pipeline (5182300).
              subPipelineFunction: [
                  {
                      $lookup: {
                          from: "b",
                          localField: "x",
                          foreignField: "y",
                          pipeline: [{$match: {$expr: {$function: {body: "function(y) { return y == 1; }", args: ["$y"], lang: "js"}}}}],
                          as: "b",
                      },
                  },
                  {$unwind: "$b"},
              ],
          };
          for (const [name, pipeline] of Object.entries(pipelines)) {
              assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: false}));
              const expected = db.a.aggregate(pipeline).toArray();
              assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: true}));
              const res = db.runCommand({aggregate: "a", pipeline: pipeline, cursor: {}});
              assert.commandWorked(res, name);
              assert.sameMembers(res.cursor.firstBatch, expected, name);
          }
      } finally {
          MongoRunner.stopMongod(conn);
      }
      
      
      
      Show
      /** * JOO tassert 5182300 / 4822878 "Unsupported (match) expression in SBE stage builder" : a $match * that classic executes fine but SBE cannot lower, placed before the first $lookup or inside a * $lookup sub-pipeline, is pushed into a join node's CanonicalQuery and lowered to SBE anyway. * * createCQForJoinPipeline() marks every join-node CanonicalQuery SBE-compatible unconditionally; * the eligibility checks only reject $text. Without join optimization these pipelines run in the * classic engine and succeed. */ const conn = MongoRunner.runMongod({ setParameter: { internalEnableJoinOptimization: true , featureFlagPathArrayness: true , featureFlagCostBasedRanker: true , }, }); const db = conn.getDB( "test" ); try { assert.commandWorked(db.a.insertMany([{_id: 1, x: 1}, {_id: 2, x: 2}])); assert.commandWorked(db.b.insertMany([{_id: 1, y: 1}, {_id: 2, y: 2}])); assert.commandWorked(db.a.createIndex({x: 1})); assert.commandWorked(db.b.createIndex({y: 1})); const lookup = {$lookup: {from: "b" , localField: "x" , foreignField: "y" , as: "b" }}; const pipelines = { // $getField in a $match $expr before the $lookup (5182300). getField: [{$match: {$expr: {$eq: [{$getField: {field: "x" , input: "$$ROOT" }}, 1]}}}, lookup, {$unwind: "$b" }], // $jsonSchema before the $lookup (4822878). jsonSchema: [{$match: {$jsonSchema: {properties: {x: {bsonType: " int " }}}}}, lookup, {$unwind: "$b" }], // $ function in the $lookup sub-pipeline (5182300). subPipelineFunction: [ { $lookup: { from: "b" , localField: "x" , foreignField: "y" , pipeline: [{$match: {$expr: {$ function : {body: " function (y) { return y == 1; }" , args: [ "$y" ], lang: "js" }}}}], as: "b" , }, }, {$unwind: "$b" }, ], }; for ( const [name, pipeline] of Object .entries(pipelines)) { assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: false })); const expected = db.a.aggregate(pipeline).toArray(); assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: true })); const res = db.runCommand({aggregate: "a" , pipeline: pipeline, cursor: {}}); assert.commandWorked(res, name); assert.sameMembers(res.cursor.firstBatch, expected, name); } } finally { MongoRunner.stopMongod(conn); }
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      A $match that SBE cannot lower ($function, $getField, $convert, $type, $jsonSchema, ...) placed before the first $lookup or inside a $lookup sub-pipeline is pushed into a join node's CanonicalQuery and lowered anyway. Eligibility only rejects $text; createCQForJoinPipeline() marks the CQ SBE-compatible without inspecting the filter. Without join optimization these pipelines run in classic and succeed.

      assert: command failed: { "errmsg" : "Unsupported expression in SBE stage builder: $getField", "code" : 5182300, "codeName" : "Location5182300" }
      Tripwire assertion: src/mongo/db/query/stage_builder/sbe/gen_expression.cpp:4372 ExpressionPostVisitor::unsupportedExpression
      

            Assignee:
            Max Verbinnen
            Reporter:
            Max Verbinnen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: