viirya opened a new pull request, #60476:
URL: https://github.com/apache/spark/pull/60476

   ### What changes were proposed in this pull request?
   
   The code generated by `ShuffledHashJoinExec` referenced the plan node 
itself, via
   `ctx.addReferenceObj("plan", this)`, to call `buildHashedRelation` when 
building the hashed
   relation of the build side.
   
   This PR moves building the relation into a new 
`ShuffledHashJoinRelationBuilder`, which holds only
   what it needs: the build-side join keys bound to the build-side output, 
whether null keys must be
   kept (build-side outer and full outer joins), and whether duplicated keys 
can be ignored. The
   generated code now references this builder instead of the plan node. The 
build metrics are not
   held by the builder; the generated code passes the plan's registered 
`SQLMetric`s to it. The
   interpreted path (`doExecute`) uses the same builder, and the now unused
   `ShuffledHashJoinExec.buildHashedRelation` is removed.
   
   This is the shuffled hash join counterpart of SPARK-61661 
(`HashAggregateExec`). Unlike
   `SortExec`/`SortMergeJoinExec`, the node keeps no mutable state that the 
generated code or another
   operator reads, so nothing else has to move.
   
   ### Why are the changes needed?
   
   The references of the generated code are serialized into every task binary 
and deserialized by
   every task. A reference to the join node carries both child subtrees, 
through the exchanges below
   the join down to the scans, although building the relation reads none of it. 
On plans with many
   expressions below the join this dominates task binary deserialization.
   
   Measured in local mode (local[8], 64 + 16 map tasks and 200 shuffled hash 
join tasks per query,
   AQE off): task binary deserialization time and binary size, both the mean 
per task over all tasks
   of 10 iterations of each query:
   
   | Query | before | after |
   |---|---|---|
   | `range` join on `id % 1000`, 2 columns | 514 us, 38 KB | 323 us, 31 KB |
   | 70 + 25 CASE columns, inner join with a non-equi condition | 1,939 us, 203 
KB | 429 us, 94 KB |
   | the same, full outer join | 1,908 us, 217 KB | 436 us, 109 KB |
   
   Executors in cluster mode deserialize the same task binary per task, so the 
saving applies there
   as well.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No.
   
   ### How was this patch tested?
   
   Added a test in `WholeStageCodegenSuite` that serializes what the shuffled 
hash join codegen stage
   adds to the task binary, for inner, stream-side outer, build-side outer, 
full outer, semi and anti
   joins with both build sides, with and without 
`spark.sql.execution.usePartitionEvaluator`, and
   asserts that no `SparkPlan` is written. It fails without this change.
   
   Ran `WholeStageCodegenSuite`, `JoinSuite`, `OuterJoinSuite`, 
`InnerJoinSuite`,
   `ExistenceJoinSuite`, `SQLMetricsSuite`, `HashedRelationSuite`, 
`AdaptiveQueryExecSuite` and
   `JoinHintSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus 5.5)
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to