|
16 | 16 | */ |
17 | 17 | package org.apache.calcite.adapter.enumerable; |
18 | 18 |
|
| 19 | +import java.util.concurrent.atomic.AtomicReference; |
| 20 | + |
| 21 | +import org.apache.calcite.adapter.jdbc.JdbcConvention; |
19 | 22 | import org.apache.calcite.plan.RelOptCluster; |
20 | 23 | import org.apache.calcite.plan.RelOptRuleCall; |
21 | 24 | import org.apache.calcite.plan.RelRule; |
| 25 | +import org.apache.calcite.plan.RelTrait; |
| 26 | +import org.apache.calcite.plan.RelTraitSet; |
22 | 27 | import org.apache.calcite.rel.RelNode; |
23 | 28 | import org.apache.calcite.rel.core.CorrelationId; |
24 | 29 | import org.apache.calcite.rel.core.Join; |
@@ -80,10 +85,38 @@ public EnumerableBatchNestedLoopJoinRule(RelBuilderFactory relBuilderFactory, |
80 | 85 | @Override public boolean matches(RelOptRuleCall call) { |
81 | 86 | Join join = call.rel(0); |
82 | 87 | JoinRelType joinType = join.getJoinType(); |
83 | | - return joinType == JoinRelType.INNER |
| 88 | + return (joinType == JoinRelType.INNER |
84 | 89 | || joinType == JoinRelType.LEFT |
85 | 90 | || joinType == JoinRelType.ANTI |
86 | | - || joinType == JoinRelType.SEMI; |
| 91 | + || joinType == JoinRelType.SEMI ) |
| 92 | + && !containsSingleJdbcSource(join, new AtomicReference<>()); |
| 93 | + } |
| 94 | + |
| 95 | + private boolean containsSingleJdbcSource(RelNode node, AtomicReference<JdbcConvention> jdbcConvention) { |
| 96 | + List<RelNode> inputs = node.getInputs(); |
| 97 | + if ( inputs.isEmpty()) { |
| 98 | + RelTraitSet traitSet = node.getTraitSet(); |
| 99 | + for ( int i = 0; i < traitSet.size(); i++) { |
| 100 | + RelTrait trait = traitSet.get(i); |
| 101 | + if ( trait instanceof JdbcConvention ) { |
| 102 | + JdbcConvention jdbcTrait = (JdbcConvention) trait; |
| 103 | + if ( jdbcConvention.get() == null){ |
| 104 | + jdbcConvention.set(jdbcTrait); |
| 105 | + return true; |
| 106 | + } else { |
| 107 | + return jdbcConvention.get() == jdbcTrait; |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + return false; |
| 112 | + } else { |
| 113 | + for ( RelNode input : inputs) { |
| 114 | + if ( !containsSingleJdbcSource(input.stripped(), jdbcConvention)) { |
| 115 | + return false; |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + return true; |
87 | 120 | } |
88 | 121 |
|
89 | 122 | @Override public void onMatch(RelOptRuleCall call) { |
|
0 commit comments