Repository navigation
MDEV-41650: COALESCE with typeless NULL changes hex literal Boolean evaluation - #5969
Open
Omar-Abdo1 wants to merge 1 commit into
Open
Omar-Abdo1 wants to merge 1 commit into
Omar-Abdo1 wants to merge 1 commit into
Conversation
…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
force-pushed
the
MDEV-41650-coalesce-hex
branch
from
October 23, 2026 19:22
e8d4c4b to
6f0d613
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A hybrid hex literal like
0x30evaluates toTRUEin a numeric context (48) butFALSEin a string context ('0').When passed through
COALESCE(NULL, 0x30),COALESCEinherited the genericItem::val_bool()method. This evaluated the result as a string, changing its Boolean evaluation fromTRUEtoFALSE(e.g., in anXORoperation).Fix: Added a custom
val_bool()implementation toItem_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
IFNULLandCASEsuffer from the same type-resolution issue because they rely onaggregate_for_result(), which defaults the result type toSTRING_RESULT. I have documented this in the test file and asked on the JIRA ticket whether a localizedval_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.COALESCE('0', 5),COALESCE(0.5, 'abc')) and nested calls to ensure no side effects.IFNULLandCASE.Regression Testing: Ran
main.func_misc,main.func_op,main.type_hex_hybrid,main.case, andmain.func_if— all pass.