Skip to content

Add support for spilling in hash joins #2545

Open

Description

@andygrove

What is the problem the feature request solves?

One of the major limitations of Comet today is that there is no spilling support for hash joins. We have to manually disable hash join support for queries that cause OOM during hash joins, which isn't ideal.

Describe the potential solution

No response

Additional context

No response

Activity

  1. added this to the 1.0.0 milestone on Oct 10, 2025
  2. removed this from the 1.0.0 milestone on Apr 18, 2026
  3. dwsmith1983 commented on Sep 28, 2026

    @dwsmith1983
    Contributor

    I'll take the Comet side of this. The operator work is upstream now: jayzhan211's epic (apache/datafusion#24768), with a sort-merge fallback under memory pressure as its first step (apache/datafusion#25217), and #6309 points the roadmap there, so nothing here should duplicate it.

    Two Comet pieces:

    1. A size guard in RewriteJoin. Today spark.comet.exec.forceShuffledHashJoin rewrites every eligible sort-merge join, and getOptimalBuildSide reads sizeInBytes only to pick the build side. Rewriting only when the build side's estimate is under a threshold, the way Spark's JoinSelection gates shuffled hash join with canBuildLocalHashMapBySize, keeps the hash join for the joins that fit, which is where the TPC-H gain is, and leaves the rest on sort-merge join until spilling lands. Small change, no native code.

    2. Once feat: sort-merge fallback for partitioned hash joins under memory pressure datafusion#25217 lands and Comet takes that DataFusion release: the Comet side of the fallback (its metrics, the fair_unified interaction, and a memory-limited join matrix on TPC-H and TPC-DS like feat(benchmarks): Record the join failure matrix under a fixed memory budget datafusion#24779), so the hash join can go on by default.

    @andygrove is that the split you want, or should Comet wait for the fallback?

  4. dwsmith1983 commented on Sep 29, 2026

    @dwsmith1983
    Contributor

    The first piece, the size guard in RewriteJoin, is up as #6384. With spark.comet.exec.forceShuffledHashJoin on, a sort-merge join is rewritten only when the build side's estimate is under a limit, by default Spark's own canBuildLocalHashMapBySize rule (autoBroadcastJoinThreshold times the shuffle partition count). Larger joins keep the sort-merge join, still native, with the reason in the plan info. spark.comet.exec.forceShuffledHashJoin.maxBuildSize sets a fixed limit or turns it off, and the two hash join benchmark configs set it to -1 so they keep measuring every join.

    The second piece waits for apache/datafusion#25217.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions