Skip to content

Planner: one exhaustive answer to "which variables does this pattern read" #2458

Open

Description

@bplatz

Problem

The planner builds several sets of "variables a later operator reads", each by hand: collect_var_stats (which variables are join variables), the live set a join step trims its output to (where_plan.rs), and the range-semijoin fold's "read elsewhere" test. When one of them misses a reader, the column that reader needs is trimmed, or the variable isn't treated as a join variable, and a join silently becomes a cartesian product. The query returns wrong rows with no error.

This has happened four times, each fixed at the one site that missed a reader:

Proposal

One exhaustive method that answers which variables a pattern, or a pending filter or bind, reads, and have collect_var_stats, the live set and the fold's read_elsewhere all call it, instead of each enumerating pattern kinds. A new pattern kind then has one place to declare its readers, and a match over all pattern kinds there (no _ arm) makes a new kind a compile error until it does.

Done when

  • The three sites derive their reader sets from the one method.
  • Adding a pattern kind fails to compile until the method handles it.
  • The existing regressions for the four instances above still pass.

Context

Raised in #2425's review.

Activity

  1. added
    enhancement
    P2
    area:query
    on Nov 19, 2026
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

    P2area:queryenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions