Skip to content

MDEV-39194 SUM(b'1100') and SUM(DISTINCT b'1100') return different numeric results for the same BIT literal (e.g. 12 vs 9) - #5717

Open
DerZc wants to merge 1 commit into
MariaDB:11.4from
DerZc:fix-mdev-39194
Open

DerZc wants to merge 1 commit into
MariaDB:11.4from
DerZc:fix-mdev-39194

Conversation

@DerZc

@DerZc DerZc commented Sep 21, 2026

Copy link
Copy Markdown

SUM(DISTINCT b'1100') can produce a different numeric value from SUM(b'1100'), despite both aggregating the same bit literal. The DISTINCT expression should return 12.

Bug report: https://jira.mariadb.org/browse/MDEV-39194

Root cause

The DISTINCT temporary field is chosen from the argument's type handler and metadata. That can materialize a bit literal in a representation that disagrees with the aggregate's numeric conversion and subsequent value consumption.

Changes

  • Choose the DISTINCT numeric temporary field using the aggregate's type handler and metadata.
  • Retain the existing temporary-table and Unique-based deduplication path.

Regression coverage

The regression evaluates SUM(DISTINCT b'1100') and checks the numeric result 12.

  • mysql-test/main/sum_distinct_bit_literal.result
  • mysql-test/main/sum_distinct_bit_literal.test

Validation

On 11.4 at d10e5d726799b1cd57cc866f40aad68c720803da:

  • The server build passed.
  • main.sum_distinct_bit_literal failed on the unchanged target branch and passed with this fix.
  • Existing MTR tests passed: main.func_group, main.group_by, main.select, main.type_bit, main.type_bit_innodb, main.type_decimal, main.type_float.
  • MTR reported no test-state cleanup failures.
  • The full regression suite was not run.

@CLAassistant

CLAassistant commented Sep 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…meric results for the same BIT literal (e.g. 12 vs 9)

SUM(DISTINCT b'1100') can produce a different numeric value from
SUM(b'1100'), despite both aggregating the same bit literal. The
DISTINCT expression should return 12.

The DISTINCT temporary field is chosen from the argument's type handler
and metadata. That can materialize a bit literal in a representation
that disagrees with the aggregate's numeric conversion and subsequent
value consumption.

Choose the DISTINCT numeric temporary field using the aggregate's type
handler and metadata. Retain the existing temporary-table and
Unique-based deduplication path.

The regression evaluates SUM(DISTINCT b'1100') and checks the numeric
result 12.

Bug report: https://jira.mariadb.org/browse/MDEV-39194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants