Skip to content

MDEV-40877 Wrong result from NOT IN with a NULL in a materialized subquery - #5718

Open
DerZc wants to merge 1 commit into
MariaDB:11.4from
DerZc:fix-mdev-40877
Open

DerZc wants to merge 1 commit into
MariaDB:11.4from
DerZc:fix-mdev-40877

Conversation

@DerZc

@DerZc DerZc commented Sep 21, 2026

Copy link
Copy Markdown

NOT IN can return a row that should be excluded when a materialized subquery contains NULL and the outer value cannot be represented by the subquery's index key type. For example, outer INT value 9999 compared with a TINYINT subquery containing 21 and NULL must not pass the predicate.

Bug report: https://jira.mariadb.org/browse/MDEV-40877

Root cause

A failed conversion of the outer value into an exact-lookup key immediately returns FALSE for IN. This bypasses the NULL-aware partial-match phase, although failure of an exact lookup does not rule out an UNKNOWN result caused by NULL in the subquery.

Changes

  • Skip the exact index lookup when key conversion fails.
  • Continue through the existing NULL-aware partial-match handling instead of returning FALSE early.
  • Preserve successful exact lookups and the materialized-subquery execution strategy.

Regression coverage

The regression compares INT values, including 9999, with a materialized TINYINT subquery containing NULL and expects no rows from NOT IN.

  • mysql-test/main/not_in_materialized_null.result
  • mysql-test/main/not_in_materialized_null.test

Validation

On 11.4 at d10e5d726799b1cd57cc866f40aad68c720803da:

  • The server build passed.
  • main.not_in_materialized_null failed on the unchanged target branch and passed with this fix.
  • Existing MTR tests passed: main.select, main.subselect.
  • MTR reported no test-state cleanup failures.
  • The full regression suite was not run.

@CLAassistant

CLAassistant commented Sep 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…query

NOT IN can return a row that should be excluded when a materialized
subquery contains NULL and the outer value cannot be represented by the
subquery's index key type. For example, outer INT value 9999 compared
with a TINYINT subquery containing 21 and NULL must not pass the
predicate.

A failed conversion of the outer value into an exact-lookup key
immediately returns FALSE for IN. This bypasses the NULL-aware
partial-match phase, although failure of an exact lookup does not rule
out an UNKNOWN result caused by NULL in the subquery.

Skip the exact index lookup when key conversion fails. Continue through
the existing NULL-aware partial-match handling instead of returning
FALSE early. Preserve successful exact lookups and the
materialized-subquery execution strategy.

The regression compares INT values, including 9999, with a materialized
TINYINT subquery containing NULL and expects no rows from NOT IN.

Bug report: https://jira.mariadb.org/browse/MDEV-40877
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.

2 participants