MDEV-32868 SELECT NULL,NULL IN (SUBQUERY) returns 0 instead of NULL #4550
+101
−0
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.
When evaluating (SELECT NULL, NULL) IN (SELECT 1, 2 FROM t), the result was incorrectly 0 instead of NULL.
The IN-to-EXISTS transformation wraps comparison predicates with trigcond() guards:
WHERE trigcond(NULL = 1) AND trigcond(NULL = 2)
During optimization, make_join_select() extracted this as a "constant condition" (used_tables() = 0) and evaluated it. With guards ON, the condition evaluated to FALSE (NULL treated as FALSE), triggering "Impossible WHERE". At runtime, guards would be turned OFF for NULL columns, but the optimizer had already marked the subquery as returning no rows.
Fix: Override used_tables() in Item_func_trig_cond to include RAND_TABLE_BIT. This prevents trigcond() from being extracted as a constant condition, deferring evaluation to runtime when guards have correct values.