Uh oh!
There was an error while loading. Please reload this page.
[GLUTEN-4421][VL] Disable flushable aggregate when input is already partitioned by grouping keys - #4443
Conversation
zhztheplayer
commented
Jan 18, 2024
/Benchmark Velox |
Run Gluten Clickhouse CI |
There was a problem hiding this comment.
Later we may develop a new way to arrange these gluten-it CI jobs. The yaml file size is exploding.
Run Gluten Clickhouse CI |
zhztheplayer
commented
Jan 18, 2024
/Benchmark Velox |
GlutenPerfBot
commented
Jan 18, 2024
===== Performance report for TPCH SF2000 with Velox backend, for reference only ====
|
5638614 to
43fb07bCompareRun Gluten Clickhouse CI |
Run Gluten Clickhouse CI |
zhztheplayer
commented
Jan 19, 2024
/Benchmark Velox |
Run Gluten Clickhouse CI |
ulysses-you
commented
Jan 19, 2024
I'm trying to understand this issue, please correct me if wrong. What we want to fix in this pr is: do not convert regular to flushable agg (2) because the flushable agg would output more than one group for the same group and then cause the partial count accumulator (3) bigger than expected. |
GlutenPerfBot
commented
Jan 19, 2024
===== Performance report for TPCH SF2000 with Velox backend, for reference only ====
|
zhztheplayer
commented
Jan 19, 2024
It's more or less similar to the issue this PR is trying to solve. Except that Q38 generates plan like the following: In Spark 3.2 the agg (1) can be flushable since there was another distinct aggregation generated on reducer side: That's why the issue is found starting from Spark 3.3. There might be some new optimizations from vanilla Spark. |
zhztheplayer
commented
Jan 19, 2024
BTW, forgot to mention that current code should already be able to handle this case without this patch (we convert agg to flushable agg only when it's the one close to shuffle). But still thanks for taking the example which is valuable anyway. |
ulysses-you
commented
Jan 19, 2024
The optimization since Spark3.3 is due to the pr apache/spark#35779. So we should not convert regular to flushable agg if it is a group by only aggreagate and it's adjacent parent is a partial aggregate ? |
zhztheplayer
commented
Jan 19, 2024
Thanks for the information. I think we indeed could forbid flushing on the case apache/spark#35779 optimizes against, although I am thinking whether the patch could provide a more general fix. When an aggregate can be considered to emit distinct data and so propagate "distinct attributes", the distinct aggregation must be a "final distinct aggregation", which means it has to process data that are already partitioned by the distinct keys. Base on this assumption, the patch could be a correct fix (Correct me if I was wrong, indeed). Additionally, the fix could be considered "general" since it's not limited to distinct aggregation. For example, a partial sum agg could produce meaningful data for a specific grouping set when it is handling input that was already partitioned by grouping keys. This may not be a good example since I doubt Catalyst planner never creates plan related to this case, but anyway the principle here is to be more careful to use flushable aggregation since vanilla Spark doesn't have this kind of optimization as of now. |
Run Gluten Clickhouse CI |
ulysses-you
commented
Jan 19, 2024
This pr is a kind of conservative fix for the issue, that means it can fix the issue but may miss optimize some other cases, e.g., if the agg is on the top of a shuffled join with the same keys, then the partial agg would not be converted to flushable. I'm fine to fix it first since it's a data correctness issue, and do further optimization in next pr. |
zhztheplayer
commented
Jan 19, 2024
I understand your point. And I think this kind of plan is not able to be optimized within flushable agg even without the patch. So let's keep enhancing the rule to cover more cases like that in further development iterations. |
zhztheplayer
commented
Jan 19, 2024
Thanks for reviewing! |
GlutenPerfBot
commented
Jan 19, 2024
===== Performance report for TPCH SF2000 with Velox backend, for reference only ====
|
If child output already partitioned by aggregation keys (this function returns true), we should avoid the optimization converting to flushable aggregation.
For example, if input is hash-partitioned by keys (a, b) and aggregate node requests "group by a, b, c", then the aggregate should NOT flush as the grouping set (a, b, c) will be created only on a single partition among the whole cluster. Spark's planner may use this information to perform optimizations like doing "partial_count(a, b, c)" directly on the output data.
This fixes#4421