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

Fix SBE bit-test operators to match classic engine for Decimal values

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.0-rc0
    • Affects Version/s: None
    • Component/s: Query Execution
    • None
    • Fully Compatible
    • ALL
    • Query Execution 2021-05-03

      This was caught by the aggregation_multiversion_fuzzer, but I distilled it into a simple handwritten repro:

      // Minimized repro inspired by this failing aggregation_multiversion_fuzzer task:
      //
      // https://spruce.mongodb.com/task/mongodb_mongo_master_enterprise_rhel_80_64_bit_dynamic_required_aggregation_multiversion_fuzzer_2_enterprise_rhel_80_64_bit_dynamic_required_patch_4fb8fa99ad6bda23030204ef29fb8cbfffc19082_6073178fa4cf4727fc7e2cd5_21_04_11_15_37_25/tests?execution=0&sortBy=STATUS&sortDir=ASC
      (function() {
      
      function createCollectionAndRunProblemQuery(conn) {
          const testDb = conn.getDB("testdb");
          const coll = testDb.test_collection;
          coll.drop();
          assert.commandWorked(coll.insert({num: NumberDecimal("220.25942974306372")}));
      
          return coll.findOne({num: {$bitsAnyClear: 10000110}});
      };
      
      let conn = MongoRunner.runMongod();
      assert.neq(null, conn, "failed to start");
      const withoutSbe = createCollectionAndRunProblemQuery(conn);
      MongoRunner.stopMongod(conn);
      
      conn = MongoRunner.runMongod({setParameter: "featureFlagSBE=true"});
      const withSbe = createCollectionAndRunProblemQuery(conn);
      MongoRunner.stopMongod(conn);
      
      assert.eq(withoutSbe, withSbe);
      }());
      

      Running this repro shows that for the example $bitsAnyClear match expression, the document matches when SBE is off but fails to match when SBE is on. The bitwise operations predate the introduction of NumberDecimal, so it's quite possible that the behavior prior to SBE was incidental – why would you do bitwise operations against a NumberDecimal anyway?

      Looking at the code quite quickly, my guess is that SBE is bailing out here:

      https://github.com/mongodb/mongo/blob/4c166a537d7442cc58eea6df09d1721fa75d7b9b/src/mongo/db/exec/sbe/vm/vm.cpp#L1637-L1642

            Assignee:
            andrew.paroski@mongodb.com Drew Paroski
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: