Skip to content
/ server Public

MDEV-39199: Fix incorrect LEFT JOIN result with INT UNIQUE key and DOUBLE literal#4878

Open
itzanway wants to merge 1 commit intoMariaDB:mainfrom
itzanway:fix-left-join-double-cast
Open

MDEV-39199: Fix incorrect LEFT JOIN result with INT UNIQUE key and DOUBLE literal#4878
itzanway wants to merge 1 commit intoMariaDB:mainfrom
itzanway:fix-left-join-double-cast

Conversation

@itzanway
Copy link
Copy Markdown
Contributor

Description

Fixes an optimizer bug where a LEFT JOIN with an ON predicate comparing an INT UNIQUE column to a DOUBLE literal (e.g., 0.1) incorrectly matches the row where the integer is 0.

Root Cause

The optimizer was coercing the double literal 0.1 into the integer type for the index lookup (0). Because it matched the UNIQUE index via eq_ref/ref access, it optimized away the original ON condition. Since the strict float-to-int comparison was truncated without flagging the condition as impossible, it returned the 0 row incorrectly.

Fix

Modified [insert function name here, e.g., add_key_field] to detect lossy type conversions when building key fields from constants. If the literal cannot be stored in the field without truncation, the equality is marked as impossible, preventing the false positive index lookup.

Testing

Added MTR test left_join_type_coercion.test which asserts the correct NULL propagation on the right side of the join.

@itzanway itzanway force-pushed the fix-left-join-double-cast branch 2 times, most recently from c963806 to d8dcc60 Compare March 28, 2026 19:34
@itzanway itzanway changed the title MDEV-39196: Fix incorrect LEFT JOIN result with INT UNIQUE key and DOUBLE literal MDEV-39199: Fix incorrect LEFT JOIN result with INT UNIQUE key and DOUBLE literal Mar 28, 2026
@itzanway itzanway force-pushed the fix-left-join-double-cast branch from d8dcc60 to 3ae93c5 Compare March 28, 2026 19:38
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