Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56819

$indexOfCP returns incorrect result when searching for empty string inside empty string with non-zero start index (classic execution engine only)

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Minor Change
    • Operating System:
      ALL
    • Backport Requested:
      v5.0, v4.9, v4.4, v4.2, v4.0
    • Sprint:
      Query Execution 2021-05-31, Query Execution 2021-06-14

      Description

      This can be reproduced by starting a standalone mongod with featureFlagSBE and then running the following script:

      (function() {
      "use strict";
       
      const coll = db.c;
      coll.drop();
       
      assert.commandWorked(coll.insert({str: ""}));
       
      const pipeline =
          [{"$project": {"a": {"$indexOfCP": [{$literal: ""}, "$str", NumberLong(1)]}, "_id": 0}}];
       
      const resultsWithSbe = coll.aggregate(pipeline).toArray();
       
      function setForceClassic(val) {
          assert.commandWorked(db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: val}));
      }
       
      const resultsWithoutSbe = (function() {
          try {
              setForceClassic(true);
              return coll.aggregate(pipeline).toArray();
          } finally {
              setForceClassic(false);
          }
      }());
       
      assert.eq(resultsWithSbe, resultsWithoutSbe);
      }());
      

      This should fail with a message such as the following:

      MongoDB server version: 5.0.0-alpha0
      uncaught exception: Error: [[ { "a" : -1 }, { "a" : -1 } ]] != [[ { "a" : 0 }, { "a" : 0 } ]] are not equal :
      doassert@src/mongo/shell/assert.js:20:14
      assert.eq@src/mongo/shell/assert.js:179:9
      @repro.js:30:1
      @repro.js:1:2
      failed to load: repro.js
      exiting with code -3
      

      With SBE on, $indexOfCP is returning -1, presumably to indicate that the needle string is not found at any position in the haystack string. With SBE off, the classic engine returns 0. I haven't yet dug into exactly

        Attachments

          Activity

            People

            Assignee:
            david.storch David Storch
            Reporter:
            david.storch David Storch
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: