Merge partition preference when adding exchange nodes#11262
Merge partition preference when adding exchange nodes#11262jessesleeping merged 2 commits intoprestodb:masterfrom
Conversation
|
Any suggestions on how to test the index join plan? |
|
Could you give an example of how plans change? |
38b2bce to
b212137
Compare
|
Take the following aggregation query as an example: The previous plan has 2 repartition exchanges, partitioning on group by columns of the inner query and the outer query respectively: After this two commits, if you set session property The optimizer in the second case merged the partition preference of the inner query with the outer query. This behavior is not always optimal. It's possible that reducing the exchange increase the skewness. That's why we want to control this behavior by a session property. |
There was a problem hiding this comment.
Let's also address this.
presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AddExchanges.java
Outdated
Show resolved
Hide resolved
presto-main/src/test/java/com/facebook/presto/sql/planner/TestLogicalPlanner.java
Outdated
Show resolved
Hide resolved
|
Currently partitioning "merging" happens bottom up, e.g: when data is already partitioned on This PR essentially introduces partitioning preference merging in top-down approach. This is really valuable. However, I would change What do you think @martint ? |
I haven't looked at the code, yet, but the goal of this change (which @jessesleeping and I discussed offline a few days ago) was to make the currently unavoidable greedy choice of merging of parent preferences optional via session property. It shouldn't introduce any structural capability that didn't previously exist. |
|
We already had this behavior (i.e. mering partition preference top-down) when adding exchange for |
I think this PR only adds "merging of parent partitioning preferences" plus a switch for it. There seem to be few related topics here:
This PR seems to add 2) and 3), but not 1) I was suggesting to add 2) and combine 3) and 4) into a single switch: "reuse/merge partitioning preferences" |
|
|
@jessesleeping there are two things:
|
|
This pull request has been automatically marked as stale because it has not had recent activity. If you'd still like this PR merged, please comment on the task, make sure you've addressed reviewer comments, and rebase on the latest master. Thank you for your contributions! |
There was a problem hiding this comment.
Let's also address this.
|
After we introduced a boolean property, do we still keep the old behavior? I might be reading it wrong, but It seems that we introduced two different new behaviors? |
highker
left a comment
There was a problem hiding this comment.
Will leave it for @shixuan-fan and @arhimondr to review given I'm not really familiar with this part of logic.
75dab7e to
eaaa0a2
Compare
|
Update:
|
eaaa0a2 to
886fdc3
Compare
presto-main/src/main/java/com/facebook/presto/sql/analyzer/FeaturesConfig.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/sql/analyzer/FeaturesConfig.java
Outdated
Show resolved
Hide resolved
886fdc3 to
c2445aa
Compare
fa5bb58 to
b572b00
Compare
|
aweisberg
left a comment
There was a problem hiding this comment.
Makes sense to me. I would go with the earlier change that only touches aggregation. I'll add the other operators for exact partitioning if I don't end up doing what I am doing with exact partitioning which is bailing out of mergeWithParent immediately.
b572b00 to
afeeed0
Compare
|

Previously we only used merged partition preference when adding exchange for union. This commit allow us to merge partitioning preference when adding exchange for aggregation, window function and index join.
By merging partition preference we have chance to reduce data repartitions but may also result in increased skewness. We add a session property to control this behavior.
Current
AddExchangebehaviorWhen planning
Aggregation,MarkDistinct,RowNumberandTopNRowNumbernodes, the current logic do the following:PreferredPropertieswhich merge the partition preference of the current node and its parent. (e.g. parent requires partitioning on(col_A), current node requires partitioning on(col_A, col_B)--> merged result is partitioning on(col_A)).PreferredProperties(partition on(col_A)).(col_A, col_B)), add a remote exchange on the current requirement ((col_A, col_B)).This can result in adding extra remote exchange for certain query shape. For example:
What this PR changes
The major confusion is between (1) passing the merged preference when planning child and (2) add exchange to the child plan based on unmerged preference. This PR added a session property to control this behavior only for Aggregation nodes.
aggregation_partitioning_merging_strategyset toLEGACY, we preserve the previous behavior where we (1) pass the merged preference when planning child and (2) add exchange based on local preference.aggregation_partitioning_merging_strategyset toTOP_DOWN, we (1) pass the merged preference when planning child and (2) add exchange based on the merged preference.aggregation_partitioning_merging_strategyset toBOTTOM_UP, we (1) don't merge preference and (2) add exchange based on local preference.For example, with
partition_merging_strategyset toTOP_DOWN, the plan of the above example only has 1 remote exchange:Note that less remote exchange is not necessary always the optimal, it depends on the cardinality of partition columns.
Open discussions
With the current approach, we don't have an option to return to our previous behavior. Maybe we should add 2 flag, one is for using merged partition preference when planning child, the other one is for using merged partition preference when adding exchange for current node.LEGACY,TOP_DOWNandBOTTOM_UP.Open discussion before about controlling merging other properties and also top-down vs bottom-up partition preference (Merge partition preference when adding exchange nodes #11262 (comment)).IndexJoinandUnionis handled differently in the current logic. They handle parent partition preference on their own.Todo