Hashed index misses cross-type numeric equality for half-integer values due to inconsistent rounding in BSONElementHasher

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • ALL
    • QE 2026-05-25
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      A hashed-index equality lookup misses cross-numeric-type matches for half-integer values with an odd integer part (e.g. 1.5, 3.5, -1.5) when the same logical value is stored as both double and Decimal128. A collection scan/btree index scan returns both documents, but a hashed-index scan returns only one.

      Repro:

        const coll = db.hashed_index_cross_numeric_type_bug;
        coll.drop();
        assert.commandWorked(coll.insertMany([
            {_id: 1, a: 1.5},
            {_id: 2, a: NumberDecimal("1.5")}
        ]));
        assert.commandWorked(coll.createIndex({a: "hashed"}));
      
        // COLLSCAN: returns [1, 2]
        coll.find({a: 1.5}, {_id: 1}).hint({$natural: 1}).toArray();
      
        // Hashed index: returns [1] only 
        coll.find({a: 1.5}, {_id: 1}).hint({a: "hashed"}).toArray();
        

       

            Assignee:
            Unassigned
            Reporter:
            Projjal Chanda
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: