korlov42 commented on a change in pull request #8596:
URL: https://github.com/apache/ignite/pull/8596#discussion_r550189389
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteCorrelatedNestedLoopJoin.java
##########
@@ -117,14 +133,26 @@ public IgniteCorrelatedNestedLoopJoin(RelInput input) {
/** {@inheritDoc} */
@Override public Pair<RelTraitSet, List<RelTraitSet>>
passThroughCollation(RelTraitSet nodeTraits, List<RelTraitSet> inputTraits) {
- // We preserve left edge collation only if batch size == 1
- if (variablesSet.size() == 1)
- return super.passThroughCollation(nodeTraits, inputTraits);
-
RelTraitSet left = inputTraits.get(0), right = inputTraits.get(1);
+ // Index lookup (collation) is required for right input.
+ RelCollation rightReplace = RelCollations.of(joinInfo.rightKeys);
+
+ // We preserve left edge collation only if batch size == 1
Review comment:
```suggestion
// We preserve left edge collation only if batch size == 1
```
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteCorrelatedNestedLoopJoin.java
##########
@@ -93,14 +96,27 @@ public IgniteCorrelatedNestedLoopJoin(RelInput input) {
/** {@inheritDoc} */
@Override public List<Pair<RelTraitSet, List<RelTraitSet>>>
deriveCollation(RelTraitSet nodeTraits, List<RelTraitSet> inputTraits) {
- // We preserve left edge collation only if batch size == 1
- if (variablesSet.size() == 1)
- return super.deriveCollation(nodeTraits, inputTraits);
-
RelTraitSet left = inputTraits.get(0), right = inputTraits.get(1);
+ RelCollation leftCollation = TraitUtils.collation(left),
rightCollation = TraitUtils.collation(right);
- return
ImmutableList.of(Pair.of(nodeTraits.replace(RelCollations.EMPTY),
- ImmutableList.of(left.replace(RelCollations.EMPTY),
right.replace(RelCollations.EMPTY))));
+ if (!isPrefix(rightCollation.getKeys(), joinInfo.rightKeys))
+ return ImmutableList.of();
+
+ // We preserve left edge collation only if batch size == 1
+ if (variablesSet.size() == 1)
+ nodeTraits.replace(leftCollation);
+ else
+ nodeTraits.replace(RelCollations.EMPTY);
+
+ return ImmutableList.of(
+ Pair.of(
+ nodeTraits.replace(leftCollation),
+ ImmutableList.of(
+ left,
+ right.replace(rightCollation)
Review comment:
this replacement (for right hand) is unnecessary
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteMergeJoin.java
##########
@@ -249,38 +251,13 @@ else if (isPrefix(rightCollation.getKeys(),
joinInfo.rightKeys)) { // preserve r
return res;
}
- /**
- * Checks if there is a such permutation of all {@code elems} that is
prefix of
- * provided {@code seq}.
- *
- * @param seq Sequence.
- * @param elems Elems.
- * @return {@code true} if there is a permutation of all {@code elems}
that is prefix of {@code seq}.
- */
- private static <T> boolean isPrefix(List<T> seq, Collection<T> elems) {
- Set<T> elems0 = new HashSet<>(elems);
-
- if (seq.size() < elems0.size())
- return false;
-
- for (T e : seq) {
- if (!elems0.remove(e))
- return false;
-
- if (elems0.isEmpty())
- break;
- }
-
- return true;
- }
-
/**
* Creates collations from provided keys.
*
* @param keys The keys to create collation from.
* @return New collation.
*/
- private static RelCollation createCollation(List<Integer> keys) {
+ public static RelCollation createCollation(List<Integer> keys) {
Review comment:
if you want it in public then it is better to move it to TraitUtils
##########
File path:
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteCorrelatedNestedLoopJoin.java
##########
@@ -93,14 +96,27 @@ public IgniteCorrelatedNestedLoopJoin(RelInput input) {
/** {@inheritDoc} */
@Override public List<Pair<RelTraitSet, List<RelTraitSet>>>
deriveCollation(RelTraitSet nodeTraits, List<RelTraitSet> inputTraits) {
- // We preserve left edge collation only if batch size == 1
- if (variablesSet.size() == 1)
- return super.deriveCollation(nodeTraits, inputTraits);
-
RelTraitSet left = inputTraits.get(0), right = inputTraits.get(1);
+ RelCollation leftCollation = TraitUtils.collation(left),
rightCollation = TraitUtils.collation(right);
- return
ImmutableList.of(Pair.of(nodeTraits.replace(RelCollations.EMPTY),
- ImmutableList.of(left.replace(RelCollations.EMPTY),
right.replace(RelCollations.EMPTY))));
+ if (!isPrefix(rightCollation.getKeys(), joinInfo.rightKeys))
Review comment:
it might be worth keeping the partial sort as well. In this case, we
will be dealing with a large range, but we will save on explicit sorting. See
IgniteMergeJoin#maxPrefix and its usage
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]