DistinctScan with embedded FETCH returns IS_EOF after a WriteConflictException during fetch

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • Fully Compatible
    • ALL
    • QE 2026-05-25, QE 2026-06-08
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The classic engine DistinctScan stage produces a premature IS_EOF when its embedded FETCH yields on a WriteConflictException (WCE). All remaining distinct groups in the query are silently dropped.

      This only manifests when the FETCH is pushed into DISTINCT_SCAN , which happens when the projected output cannot be served by the index alone.

       

      Repro:

      db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "forceClassicEngine"});
      
      const coll = db.distinct_scan_fetch_yield_retry;
      coll.drop();
      assert.commandWorked(coll.createIndex({a: 1, b: 1}));
      
      const docs = [];
      for (let a = 0; a < 10; ++a) {
          docs.push({a: a, b: 0, c: a});
          docs.push({a: a, b: 1, c: a});
      }
      assert.commandWorked(coll.insertMany(docs));
      
      const pipeline = [{$group: {_id: "$a", first: {$top: {sortBy: {a: 1, b: 1}, output: "$c"}}}}];
      
      assert.commandWorked(db.adminCommand({
          configureFailPoint: "WTWriteConflictExceptionForReads",
          mode: {activationProbability: 0.2}
      }));
      
      // Intermittently returns fewer than 10 groups.
      for (let i = 0; i < 5; ++i) {
          const results = coll.aggregate(pipeline).toArray();
          assert.eq(10, results.length, results);
      }
      

       

       

            Assignee:
            Nicola Cabiddu
            Reporter:
            Projjal Chanda
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: