[SERVER-56102] Fix SBE bit-test operators to match classic engine for Decimal values Created: 14/Apr/21  Updated: 29/Oct/23  Resolved: 29/Apr/21

Status: Closed
Project: Core Server
Component/s: Query Execution
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: David Storch Assignee: Drew Paroski
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-56326 Add a round() method to the Decimal12... Closed
is depended on by SERVER-56119 Enable generational agg and query fuz... Closed
Duplicate
is duplicated by SERVER-56084 [SBE] aggregation_multiversion_fuzzer... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query Execution 2021-05-03
Participants:

 Description   

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



 Comments   
Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-56102 Fix SBE bit-test operators to match classic engine for Decimal values
Branch: master
https://github.com/mongodb/mongo/commit/1ff00ec66697eb16b6ae089681d9f3414f950fb1

Comment by David Storch [ 14/Apr/21 ]

This one appears to be the same problem manifesting due to a bit-test match expression inside a $match in the subpipeline of a $lookup.

Comment by David Storch [ 14/Apr/21 ]

Here is a slightly different example where this appears to manifest inside the restrictWithMatch match expression of a $graphLookup. See related ticket SERVER-56084 for additional context on how this manifests with $graphLookup.

Comment by David Storch [ 14/Apr/21 ]

One more example. At this point, I'll probably stop linking any more duplicates.

Comment by David Storch [ 14/Apr/21 ]

This task appears at a glance to be another instance of the same problem, this time involving $bitsAnySet.

Generated at Thu Feb 08 05:38:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.