diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java index 2d95b0ed877c25..a769e28cbb0b19 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/PartitionExtractor.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.stream.Collectors; import com.google.common.primitives.Primitives; -import org.apache.calcite.rel.RelDistribution; import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.calcite.rex.RexCall; @@ -45,9 +44,11 @@ import org.apache.ignite.internal.processors.query.calcite.prepare.Fragment; import org.apache.ignite.internal.processors.query.calcite.prepare.IgniteRelShuttle; import org.apache.ignite.internal.processors.query.calcite.rel.IgniteIndexScan; +import org.apache.ignite.internal.processors.query.calcite.rel.IgniteReceiver; import org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel; import org.apache.ignite.internal.processors.query.calcite.rel.IgniteSender; import org.apache.ignite.internal.processors.query.calcite.rel.IgniteTableScan; +import org.apache.ignite.internal.processors.query.calcite.rel.IgniteTrimExchange; import org.apache.ignite.internal.processors.query.calcite.rel.ProjectableFilterableTableScan; import org.apache.ignite.internal.processors.query.calcite.schema.CacheTableDescriptor; import org.apache.ignite.internal.processors.query.calcite.schema.IgniteTable; @@ -81,6 +82,20 @@ public PartitionExtractor(IgniteTypeFactory typeFactory) { return rel; } + /** {@inheritDoc} */ + @Override public IgniteRel visit(IgniteTrimExchange rel) { + stack.push(PartitionAllNode.IGNORE); + + return rel; + } + + /** {@inheritDoc} */ + @Override public IgniteRel visit(IgniteReceiver rel) { + stack.push(PartitionAllNode.IGNORE); + + return rel; + } + /** {@inheritDoc} */ @Override protected IgniteRel processNode(IgniteRel rel) { IgniteRel res = super.processNode(rel); @@ -106,7 +121,7 @@ public PartitionNode go(Fragment fragment) { if (fragment.mapping() == null || !fragment.mapping().colocated()) return PartitionAllNode.INSTANCE; - visit(fragment.root()); + processNode(fragment.root()); if (stack.isEmpty()) return PartitionAllNode.INSTANCE; @@ -122,13 +137,7 @@ private void processScan(IgniteRel rel) { IgniteTable tbl = rel.getTable().unwrap(IgniteTable.class); - if (tbl.distribution().function().type() == RelDistribution.Type.BROADCAST_DISTRIBUTED) { - stack.push(PartitionAllNode.INSTANCE_REPLICATED); - - return; - } - - if (tbl.distribution().getKeys().size() != 1) { + if (!tbl.distribution().function().affinity() || tbl.distribution().getKeys().size() != 1) { stack.push(PartitionAllNode.INSTANCE); return; diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionAllNode.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionAllNode.java index e56380ebeb5134..da51c350539f03 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionAllNode.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionAllNode.java @@ -20,8 +20,8 @@ /** */ public class PartitionAllNode implements PartitionNode { - /** */ - public static final PartitionAllNode INSTANCE_REPLICATED = new PartitionAllNode(true); + /** Exclude this node from partition calculation if other nodes present in {@link PartitionParameterNode }. */ + public static final PartitionAllNode IGNORE = new PartitionAllNode(true); /** */ public static final PartitionAllNode INSTANCE = new PartitionAllNode(false); diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionOperandNode.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionOperandNode.java index 4afe1b4556f202..9ed555affb0320 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionOperandNode.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/partition/PartitionOperandNode.java @@ -43,7 +43,7 @@ private PartitionOperandNode(Operand op, List operands) { if (op == Operand.AND) { for (PartitionNode operand : operands) { - if (operand == PartitionAllNode.INSTANCE_REPLICATED) + if (operand == PartitionAllNode.IGNORE) continue; Collection parts = operand.apply(ctx); @@ -59,7 +59,7 @@ private PartitionOperandNode(Operand op, List operands) { } else { for (PartitionNode operand: operands) { - if (operand == PartitionAllNode.INSTANCE_REPLICATED) + if (operand == PartitionAllNode.IGNORE) continue; Collection parts = operand.apply(ctx);