Skip to content

MDEV-41650: COALESCE with typeless NULL changes hex literal Boolean evaluation - #5969

Open
Omar-Abdo1 wants to merge 1 commit into
MariaDB:12.3from
Omar-Abdo1:MDEV-41650-coalesce-hex
Open

Omar-Abdo1 wants to merge 1 commit into
MariaDB:12.3from
Omar-Abdo1:MDEV-41650-coalesce-hex

Conversation

@Omar-Abdo1

@Omar-Abdo1 Omar-Abdo1 commented Oct 23, 2026 •

Copy link
Copy Markdown

Description

A hybrid hex literal like 0x30 evaluates to TRUE in a numeric context (48) but FALSE in a string context ('0').

When passed through COALESCE(NULL, 0x30), COALESCE inherited the generic Item::val_bool() method. This evaluated the result as a string, changing its Boolean evaluation from TRUE to FALSE (e.g., in an XOR operation).

Fix: Added a custom val_bool() implementation to Item_func_coalesce. It now iterates through its arguments and returns the native boolean value of the first non-NULL argument, preserving the correct numeric truth value.

Systemic Bug Note:
Investigating further, I found that IFNULL and CASE suffer from the same type-resolution issue because they rely on aggregate_for_result(), which defaults the result type to STRING_RESULT. I have documented this in the test file and asked on the JIRA ticket whether a localized val_bool() fix or a deeper type-aggregation fix is preferred for those functions.

JIRA Ticket

https://jira.mariadb.org/browse/MDEV-41650

Test Coverage

A regression test is added in mysql-test/main/mdev_41650.test.

  • It verifies the original bug report query.
  • It adds controls for mixed types (COALESCE('0', 5), COALESCE(0.5, 'abc')) and nested calls to ensure no side effects.
  • It explicitly documents the current behavior of IFNULL and CASE.

Regression Testing: Ran main.func_misc, main.func_op, main.type_hex_hybrid, main.case, and main.func_if — all pass.

…valuation

COALESCE did not have a custom val_bool() implementation, causing it to fall
back to the generic Item::val_bool() which converted the hybrid hex literal
(0x30) to a string ('0') and evaluated it as FALSE.

Fix: Override val_bool() in Item_func_coalesce to iterate through its
arguments and return the native boolean value of the first non-NULL argument.

Signed-off-by: OmarAbdo <omargamer10a@gmail.com>
@Omar-Abdo1
Omar-Abdo1 force-pushed the MDEV-41650-coalesce-hex branch from e8d4c4b to 6f0d613 Compare October 23, 2026 19:22
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.

1 participant