Skip to content

Nullable expression over non-null columns are planned as non-null-aware-joins #25024

Closed

Description

@AdamGS

Describe the bug

As seen in the query below, we currently only take column nullability into consideration when planning joins instead of full expression nullability, in cases where we join on an expression that might introduce nulls.

To Reproduce

CREATE TABLE outer_t(id VARCHAR NOT NULL) AS VALUES ('z');
CREATE TABLE inner_t(id VARCHAR NOT NULL) AS VALUES ('a');

SELECT id
FROM outer_t
WHERE (NULLIF(id, 'z') NOT IN (SELECT id FROM inner_t)) IS NULL;

Expected behavior

The query above currently returns no results, but should return a single row with the value z (verified with DuckDB).

Additional context

No response

Activity

  1. added theissue type on Sep 7, 2026
  2. AdamGS commented on Sep 7, 2026

    @AdamGS
    ContributorAuthor

    take

  3. removed theissue type on Sep 7, 2026
  4. alamb commented on Oct 28, 2026

    @alamb
    Contributor

    When fixing this bug, I think we should make the query error rather than trying to make it work / give correct results. To make it work and have confidence it will be correct, I think we need a more general approach than patches. See here for details

  5. raghavyadav01 commented on Oct 29, 2026

    @raghavyadav01
    Contributor

    Checked on current main (14aa185), this returns the right row now:

    CREATE TABLE outer_t(id VARCHAR NOT NULL) AS VALUES ('z');
    CREATE TABLE inner_t(id VARCHAR NOT NULL) AS VALUES ('a');
    SELECT id FROM outer_t WHERE (NULLIF(id, 'z') NOT IN (SELECT id FROM inner_t)) IS NULL;
    -- z

    Same as DuckDB 1.5.6. I think this can be closed.

  6. alamb commented on Oct 29, 2026

    @alamb
    Contributor

    Agreed -- thank you @raghavyadav01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions