|
46 | 46 | import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
|
47 | 47 | import org.apache.doris.nereids.util.JoinUtils;
|
48 | 48 | import org.apache.doris.qe.ConnectContext;
|
| 49 | +import org.apache.doris.qe.SessionVariable; |
49 | 50 |
|
50 | 51 | import com.google.common.base.Preconditions;
|
51 | 52 | import com.google.common.collect.ImmutableList;
|
@@ -213,12 +214,12 @@ private boolean couldNotRightBucketShuffleJoin(JoinType joinType, DistributionSp
|
213 | 214 | || joinType == JoinType.FULL_OUTER_JOIN);
|
214 | 215 | boolean isSpecInScope = (leftHashSpec.getShuffleType() == ShuffleType.NATURAL
|
215 | 216 | || rightHashSpec.getShuffleType() == ShuffleType.NATURAL);
|
216 |
| - return isJoinTypeInScope && isSpecInScope; |
| 217 | + return isJoinTypeInScope && isSpecInScope && !SessionVariable.canUseNereidsDistributePlanner(); |
217 | 218 | }
|
218 | 219 |
|
219 | 220 | @Override
|
220 |
| - public Boolean visitPhysicalHashJoin(PhysicalHashJoin<? extends Plan, ? extends Plan> hashJoin, |
221 |
| - Void context) { |
| 221 | + public Boolean visitPhysicalHashJoin( |
| 222 | + PhysicalHashJoin<? extends Plan, ? extends Plan> hashJoin, Void context) { |
222 | 223 | Preconditions.checkArgument(children.size() == 2, "children.size() != 2");
|
223 | 224 | Preconditions.checkArgument(childrenProperties.size() == 2);
|
224 | 225 | Preconditions.checkArgument(requiredProperties.size() == 2);
|
@@ -303,13 +304,24 @@ public Boolean visitPhysicalHashJoin(PhysicalHashJoin<? extends Plan, ? extends
|
303 | 304 | (DistributionSpecHash) requiredProperties.get(1).getDistributionSpec()));
|
304 | 305 | } else if (leftHashSpec.getShuffleType() == ShuffleType.EXECUTION_BUCKETED
|
305 | 306 | && rightHashSpec.getShuffleType() == ShuffleType.NATURAL) {
|
306 |
| - // TODO: we must do shuffle on right because coordinator could not do right be selection in this case, |
307 |
| - // since it always to check the left most node whether olap scan node. |
308 |
| - // after we fix coordinator problem, we could do right to left bucket shuffle |
309 |
| - updatedForRight = Optional.of(calAnotherSideRequired( |
310 |
| - ShuffleType.EXECUTION_BUCKETED, leftHashSpec, rightHashSpec, |
311 |
| - (DistributionSpecHash) requiredProperties.get(0).getDistributionSpec(), |
312 |
| - (DistributionSpecHash) requiredProperties.get(1).getDistributionSpec())); |
| 307 | + if (SessionVariable.canUseNereidsDistributePlanner()) { |
| 308 | + // nereids coordinator can exchange left side to right side to do bucket shuffle join |
| 309 | + // TODO: maybe we should check if left child is PhysicalDistribute. |
| 310 | + // If so add storage bucketed shuffle on left side. Other wise, |
| 311 | + // add execution bucketed shuffle on right side. |
| 312 | + updatedForLeft = Optional.of(calAnotherSideRequired( |
| 313 | + ShuffleType.STORAGE_BUCKETED, rightHashSpec, leftHashSpec, |
| 314 | + (DistributionSpecHash) requiredProperties.get(1).getDistributionSpec(), |
| 315 | + (DistributionSpecHash) requiredProperties.get(0).getDistributionSpec())); |
| 316 | + } else { |
| 317 | + // legacy coordinator could not do right be selection in this case, |
| 318 | + // since it always to check the left most node whether olap scan node. |
| 319 | + // so we can only shuffle right to left side to do normal shuffle join |
| 320 | + updatedForRight = Optional.of(calAnotherSideRequired( |
| 321 | + ShuffleType.EXECUTION_BUCKETED, leftHashSpec, rightHashSpec, |
| 322 | + (DistributionSpecHash) requiredProperties.get(0).getDistributionSpec(), |
| 323 | + (DistributionSpecHash) requiredProperties.get(1).getDistributionSpec())); |
| 324 | + } |
313 | 325 | } else if (leftHashSpec.getShuffleType() == ShuffleType.EXECUTION_BUCKETED
|
314 | 326 | && rightHashSpec.getShuffleType() == ShuffleType.EXECUTION_BUCKETED) {
|
315 | 327 | if (bothSideShuffleKeysAreSameOrder(rightHashSpec, leftHashSpec,
|
@@ -537,20 +549,20 @@ private List<ExprId> calAnotherSideRequiredShuffleIds(DistributionSpecHash notSh
|
537 | 549 | * calAnotherSideRequiredShuffleIds's comment.
|
538 | 550 | *
|
539 | 551 | * @param shuffleType real output shuffle type
|
540 |
| - * @param notShuffleSideOutput not shuffle side real output used hash spec |
541 |
| - * @param shuffleSideOutput shuffle side real output used hash spec |
542 |
| - * @param notShuffleSideRequired not shuffle side required used hash spec |
543 |
| - * @param shuffleSideRequired shuffle side required hash spec |
| 552 | + * @param notNeedShuffleSideOutput not shuffle side real output used hash spec |
| 553 | + * @param needShuffleSideOutput shuffle side real output used hash spec |
| 554 | + * @param notNeedShuffleSideRequired not shuffle side required used hash spec |
| 555 | + * @param needShuffleSideRequired shuffle side required hash spec |
544 | 556 | * @return shuffle side new required hash spec
|
545 | 557 | */
|
546 | 558 | private PhysicalProperties calAnotherSideRequired(ShuffleType shuffleType,
|
547 |
| - DistributionSpecHash notShuffleSideOutput, DistributionSpecHash shuffleSideOutput, |
548 |
| - DistributionSpecHash notShuffleSideRequired, DistributionSpecHash shuffleSideRequired) { |
549 |
| - List<ExprId> shuffleSideIds = calAnotherSideRequiredShuffleIds(notShuffleSideOutput, |
550 |
| - notShuffleSideRequired, shuffleSideRequired); |
| 559 | + DistributionSpecHash notNeedShuffleSideOutput, DistributionSpecHash needShuffleSideOutput, |
| 560 | + DistributionSpecHash notNeedShuffleSideRequired, DistributionSpecHash needShuffleSideRequired) { |
| 561 | + List<ExprId> shuffleSideIds = calAnotherSideRequiredShuffleIds(notNeedShuffleSideOutput, |
| 562 | + notNeedShuffleSideRequired, needShuffleSideRequired); |
551 | 563 | return new PhysicalProperties(new DistributionSpecHash(shuffleSideIds, shuffleType,
|
552 |
| - shuffleSideOutput.getTableId(), shuffleSideOutput.getSelectedIndexId(), |
553 |
| - shuffleSideOutput.getPartitionIds())); |
| 564 | + needShuffleSideOutput.getTableId(), needShuffleSideOutput.getSelectedIndexId(), |
| 565 | + needShuffleSideOutput.getPartitionIds())); |
554 | 566 | }
|
555 | 567 |
|
556 | 568 | private void updateChildEnforceAndCost(int index, PhysicalProperties targetProperties) {
|
|
0 commit comments