Skip to content

[dbolympics] Grandparent column reference in nested subquery causes planner error #21727

Open

Description

@neilconway

Describe the bug

  CREATE TABLE t0 (g INT);
  CREATE TABLE t1 (a INT);
  CREATE TABLE t2 (c INT);
  INSERT INTO t0 VALUES (1), (2);
  INSERT INTO t1 VALUES (10);
  INSERT INTO t2 VALUES (1);

  -- Outer-outer column `t0.g` is referenced only at the deepest level
  -- (t2.c = t0.g). The middle EXISTS (over t1) has no direct reference
  -- to t0, so its Subquery.outer_ref_columns gets populated as empty.
  SELECT g FROM t0 WHERE EXISTS (
      SELECT 1 FROM t1 WHERE EXISTS (
          SELECT 1 FROM t2 WHERE t2.c = t0.g
      )
  );

-->

Schema error: No field named t0.g. Valid fields are __correlated_sq_1.c.

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Activity

  1. added theissue type on Apr 18, 2026
  2. neilconway commented on Apr 18, 2026

    @neilconway
    ContributorAuthor

    take

  3. neilconway commented on Apr 22, 2026

    @neilconway
    ContributorAuthor

    Probably a dup of #15558

  4. changed the title [-]Grandparent column reference in nested subquery causes planner error[/-] [+][dbolympics] Grandparent column reference in nested subquery causes planner error[/+] on Oct 24, 2026
  5. alamb commented on Oct 24, 2026

    @alamb
    Contributor

    Affects DB Olympics, see: #26661

  6. removed their assignment
    on Oct 24, 2026
  7. alamb commented on Oct 28, 2026

    @alamb
    Contributor

    I think we should implement support support for this feature as part of the more general subquery decorrelation project described here

    in my opinion WE SHOULD NOT try and extend the existing subquery rewrites to support this type of query as that risks introducing many more wrong results, see #5492 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions