Skip to content

HashJoinExec consumes probe side when build side is empty #20492

Description

@LiaCastaneda

Is your feature request related to a problem or challenge?

When the HashJoinExec build side returns 0 rows, the probe side stream is still fully consumed even though no output will be produced (for join types like INNER, LEFT, LEFT SEMI, etc.). We've seen queries where the probe scans +10 GB of data even when the build side returns no rows, and HashJoinExec outputs 0 rows.

The short-circuit at stream.rs:647 skips hash lookup work, but fetch_probe_batch is still called for every batch until the stream is exhausted. The transition from WaitBuildSide --> FetchProbeBatch is unconditional, there is no check after the build phase completes to decide whether the probe side needs to be polled at all.

I'm not sure if this is intentional or if anything relies on the probe side being fully consumed in this scenario. If not, it seems like after collect_build_side completes, we could drop the probe stream immediately for the join types where empty build guarantees an empty output.

Describe the solution you'd like

As mentioned by @gabotechs, one question is whether this should be gated on dynamic filtering being enabled. I'm not sure if they are orthogonal or not -- dynamic filtering pushes predicates into the probe scan to skip data, while this optimization would skip the probe scan entirely when the build is empty.

The other thing is that I'm not sure if skipping the probe side entirely could break existing assumptions, so I think the following options can be considered:

  • Avoid fetching from the probe side for all queries (when build is empty and join type guarantees empty output).
  • Avoid fetching from the probe side for all queries (when build is empty and join type guarantees empty output) only if dynamic filering is enabled
  • Put this behind an execution option for those who want this behavior in the join.

Describe alternatives you've considered

No response

Additional context

No response

Activity

  1. added a commit that references this issue on Apr 4, 2026
    6c5e241
  2. added 2 commits that reference this issue on Apr 6, 2026
    d89e9d0
    4a36e6b
  3. added 2 commits that reference this issue on Apr 16, 2026
    13c09f3
    42ecad5
  4. added a commit that references this issue on Apr 21, 2026
    9f0d6a4
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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions