ExportXMLWordPrintableJSON

    • Query Optimization
    • Fully Compatible
    • ALL
    • Hide

       

      
      /**
       * JOO tassert 11514601 "Missing estimate for winning single-table plan's root QSN": a
       * $setWindowFields with sortBy after a join-optimizable $lookup+$unwind.
       *
       * $setWindowFields desugars to {$sort: {..., $_internalOutputSortKeyMetadata: true}} followed by
       * $_internalSetWindowFields. The sort-key metadata dependency reaches the base collection
       * CanonicalQuery, the planner adds a SORT_KEY_GENERATOR on top of the access plan, and CBR has no
       * estimate for that node. A plain {$sort: {_id: 1}} suffix does not trigger it.
       */
      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 pipeline = [
              {$lookup: {from: "b", localField: "x", foreignField: "y", as: "b"}},
              {$unwind: "$b"},
              {$setWindowFields: {sortBy: {_id: 1}, output: {r: {$rank: {}}}}},
          ];
          assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: false}));
          const expected = db.a.aggregate(pipeline).toArray();
          assert.eq(expected.length, 2, tojson(expected));
          assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: true}));
          const res = db.runCommand({aggregate: "a", pipeline: pipeline, cursor: {}});
          assert.commandWorked(res);
          assert.sameMembers(res.cursor.firstBatch, expected);
      } finally {
          MongoRunner.stopMongod(conn);
      }
      
      
      

       

      Show
        /** * JOO tassert 11514601 "Missing estimate for winning single-table plan's root QSN" : a * $setWindowFields with sortBy after a join-optimizable $lookup+$unwind. * * $setWindowFields desugars to {$sort: {..., $_internalOutputSortKeyMetadata: true }} followed by * $_internalSetWindowFields. The sort-key metadata dependency reaches the base collection * CanonicalQuery, the planner adds a SORT_KEY_GENERATOR on top of the access plan, and CBR has no * estimate for that node. A plain {$sort: {_id: 1}} suffix does not trigger it. */ 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 pipeline = [ {$lookup: {from: "b" , localField: "x" , foreignField: "y" , as: "b" }}, {$unwind: "$b" }, {$setWindowFields: {sortBy: {_id: 1}, output: {r: {$rank: {}}}}}, ]; assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: false })); const expected = db.a.aggregate(pipeline).toArray(); assert.eq(expected.length, 2, tojson(expected)); assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: true })); const res = db.runCommand({aggregate: "a" , pipeline: pipeline, cursor: {}}); assert.commandWorked(res); assert.sameMembers(res.cursor.firstBatch, expected); } finally { MongoRunner.stopMongod(conn); }  
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      $setWindowFields desugars to {$sort: {..., $_internalOutputSortKeyMetadata: true}} plus $_internalSetWindowFields. The sort-key metadata dependency reaches the base collection CanonicalQuery, the planner puts a SORT_KEY_GENERATOR on top of the access plan, and CBR has no estimate for that node in single_table_access.cpp. A plain {$sort: {_id: 1}} suffix does not trigger it.

       

      assert: command failed: { "errmsg" : "Missing estimate for winning single-table plan's root QSN", "code" : 11514601, "codeName" : "Location11514601" }
      Tripwire assertion: src/mongo/db/query/compiler/optimizer/join/single_table_access.cpp:173 accessPlanForFilterWithDerivedPredicates
      

       

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

              Created:
              Updated:
              Resolved: