txwyy123 commented on PR #59841: URL: https://github.com/apache/spark/pull/59841#issuecomment-6912349397
Thanks for the second pass. Before I push the fixes for those comments, I'd like your view on how to gate the field-based path, because your first review suggested hooking into `chooseCode`, and I now think that is the better design than the size estimate I had. **What I tried.** In a prototype I added one method to `CodegenContext`, `wholeStageOperatorSplit(sources)`, for an operator whose code differs when it is split, as opposed to a block that `splitExpressionsWithSources` moves into methods. It follows the existing modes: - Record: it registers a key (from the join's output columns) and returns a marker that goes into the join's code, so `chooseCode` can tell which method the join lands in. - Split(only): it returns true when the key is selected, and bumps `wholeStageBlocksSplit` so `chooseCode` knows something was split. - Off: false, so `spark.sql.codegen.wholeStage.splitExpressions=false` gives master's code. `SortMergeJoinExec.doProduce` calls it and takes the field-based path only when it returns true. The size estimate is gone. `chooseCode` itself is unchanged. **What it does.** With `maxFields=300` and the tests' column mix, the stage was split only where it was past 8000: | Join | Result | |---|---| | 5+5, 60+60 inner | recorded, not split | | 99+2 LeftAnti | recorded, not split | | 100+100, 120+120 inner | split | | 120+120 left outer | split | | 200+5, 220+5 semi; 220+5, 240+5 anti | split | So the 99+2 LeftAnti you pointed out no longer takes the field path. The 12 new tests and WholeStageCodegenSuite, JoinSuite, OuterJoinSuite, InnerJoinSuite and ExistenceJoinSuite pass together: 778 succeeded, 0 failed. The catalyst codegen suites (CodeGenerationSuite, CodeGeneratorWithInterpretedFallbackSuite and the `codegen` package) pass too: 197 succeeded, 0 failed. **Cost.** I timed `doCodeGen()` plus the compile for each stage. Narrow joins show no measurable difference against the estimate version: the recorded trial compile is the one `doExecute` finds in the cache. Joins that get split pay one extra compile, the unsplit trial: about 17 ms more per wide query on a warm JVM (roughly 55 ms against 39 ms for five stages). That is one time per distinct plan, and the decision is remembered. **Questions.** 1. Are you comfortable with an operator-level hook in `CodegenContext`, or would you rather this stay out of catalyst? 2. Should narrow joins record at all? A cheap pre-filter on column count would avoid the trial compile for them, but I have not found it necessary. 3. The fix is only active while `spark.sql.codegen.wholeStage.splitExpressions` is true, which is the default in 4.4.0. Is that acceptable? If you prefer the hook, I'll replace the estimate in this PR with it and update the description. If you'd rather keep the change in `joins/`, the estimate version (per-type bytes per output column, 20% headroom) is ready as the fallback. -- 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]
