Skip to content
/ server Public

Conversation

@Olernov
Copy link
Contributor

@Olernov Olernov commented Jan 16, 2026

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.

Copy link
Member

@spetrunia spetrunia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() evaluated this as a "constant
condition". 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: check can_eval_in_optimize() instead of is_expensive() in
make_join_select(). Unlike is_expensive(), can_eval_in_optimize()
also verifies const_item(), which returns FALSE for Item_func_trig_cond
Switch branches of the `if` condition to make the code
flow more naturally.
@Olernov Olernov force-pushed the 10.11-MDEV-32868-null-subq branch from cbb7441 to 3811b51 Compare January 27, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants