Skip to content

The BITCOUNT function incorrectly counts BINARY/VARBINARY values of >=16 bytes. #3645

@davidjacooper

Description

@davidjacooper

BITCOUNT(X'ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00') returns 120 rather than the expected value of 64. It appears to be double counting the 2nd-to-8th bytes, and ignoring the 10th-to-16th bytes.

Removing the last 00 will stop this behaviour and cause it to return 64. Adding another 8 zero bytes will cause it to triple-count many of the ff bytes.

I think I know why. In BitFunction.bitCount(), I believe the line reading c += Long.bitCount(Bits.readLong(bytes, i)); should actually be c += Long.bitCount(Bits.readLong(bytes, i << 3));.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions