korlov42 commented on a change in pull request #8959: URL: https://github.com/apache/ignite/pull/8959#discussion_r608394347
########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/RuntimeIndex.java ########## @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.query.calcite.exec; + +/** + * Runtime sorted index based on on-heap tree. Review comment: outdated javadoc ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/RuntimeHashIndex.java ########## @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ignite.internal.processors.query.calcite.exec; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.function.Supplier; + +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.ignite.internal.processors.query.calcite.exec.exp.agg.GroupKey; +import org.apache.ignite.internal.util.typedef.F; +import org.jetbrains.annotations.NotNull; + +/** + * Runtime sorted index based on on-heap tree. Review comment: copy-pasted javadoc ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/RuntimeTreeIndex.java ########## @@ -87,7 +87,7 @@ public void push(Row r) { rows.clear(); } - /** {@inheritDoc} */ Review comment: seems this change is unnecessary ########## File path: modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/CorrelatedNestedLoopJoinPlannerTest.java ########## @@ -86,9 +86,11 @@ public void testValidIndexExpressions() throws Exception { IgniteRel phys = physicalPlan( sql, publicSchema, - "MergeJoinConverter", "NestedLoopJoinConverter", "FilterSpoolMergeRule" + "MergeJoinConverter", "NestedLoopJoinConverter" ); + System.out.println("+++ " + RelOptUtil.toString(phys)); Review comment: debug output ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/RuntimeTreeIndex.java ########## @@ -103,10 +103,7 @@ else if (ectx.rowHandler().get(firstCol, lower) != null && ectx.rowHandler().get return new Cursor(rows); } - /** Review comment: this should be reverted too ########## File path: modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/AbstractPlannerTest.java ########## @@ -264,6 +264,8 @@ protected IgniteRel physicalPlan(String sql, IgniteSchema publicSchema, String.. try { IgniteRel res = planner.transform(PlannerPhase.OPTIMIZATION, desired, rel); +// System.out.println(planner.dump()); Review comment: debug ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteCorrelatedNestedLoopJoin.java ########## @@ -106,7 +106,7 @@ public IgniteCorrelatedNestedLoopJoin(RelInput input) { List<Integer> newRightCollationFields = maxPrefix(rightCollation.getKeys(), joinInfo.leftKeys); if (F.isEmpty(newRightCollationFields)) Review comment: we could preserve a left collation even if `newRightCollationFields` is empty, thus it's better to remove this check ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteHashIndexSpool.java ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.query.calcite.rel; + +import java.util.List; + +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelOptCost; +import org.apache.calcite.plan.RelOptPlanner; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelInput; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelWriter; +import org.apache.calcite.rel.core.Spool; +import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCost; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCostFactory; +import org.apache.ignite.internal.processors.query.calcite.util.RexUtils; +import org.apache.ignite.internal.util.typedef.F; + +/** + * Relational operator that returns the sorted contents of a table + * and allow to lookup rows by specified bounds. + */ +public class IgniteHashIndexSpool extends Spool implements IgniteRel { + /** Search row. */ + private final List<RexNode> searchRow; + + /** Search row. */ + private final ImmutableBitSet keys; + + /** Condition (used to calculate selectivity). */ + private final RexNode cond; + + /** */ + public IgniteHashIndexSpool( + RelOptCluster cluster, + RelTraitSet traits, + RelNode input, + List<RexNode> searchRow, + RexNode cond + ) { + super(cluster, traits, input, Type.LAZY, Type.EAGER); + + assert !F.isEmpty(searchRow); + + this.searchRow = searchRow; + this.cond = cond; + + keys = ImmutableBitSet.of(RexUtils.notNullKeys(searchRow)); + } + + /** + * Constructor used for deserialization. + * + * @param input Serialized representation. + */ + public IgniteHashIndexSpool(RelInput input) { + this(input.getCluster(), + input.getTraitSet().replace(IgniteConvention.INSTANCE), + input.getInputs().get(0), + input.getExpressionList("searchRow"), + null Review comment: is it ok that condition is null? ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/trait/TraitUtils.java ########## @@ -452,7 +453,7 @@ else if (!fillRecursive(outTraits, inTraits, result, combination, idx + 1)) * @param keys The keys to create collation from. * @return New collation. */ - public static RelCollation createCollation(List<Integer> keys) { + public static RelCollation createCollation(Collection<Integer> keys) { Review comment: I don't think it's a good idea to change the type of the param to `Collection`. Collation is supposed to have some order and this is unclear which order will be in case we pass a `Set`, for instance ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteHashIndexSpool.java ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.query.calcite.rel; + +import java.util.List; + +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelOptCost; +import org.apache.calcite.plan.RelOptPlanner; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelInput; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelWriter; +import org.apache.calcite.rel.core.Spool; +import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCost; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCostFactory; +import org.apache.ignite.internal.processors.query.calcite.util.RexUtils; +import org.apache.ignite.internal.util.typedef.F; + +/** + * Relational operator that returns the sorted contents of a table Review comment: copy-pasted javadoc ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/RuntimeTreeIndex.java ########## @@ -71,7 +71,7 @@ public RuntimeTreeIndex( /** * Add row to index. Review comment: /** {@inheritDoc} */ ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteCorrelatedNestedLoopJoin.java ########## @@ -149,13 +146,13 @@ public IgniteCorrelatedNestedLoopJoin(RelInput input) { baseTraits.getKey(), ImmutableList.of( baseTraits.getValue().get(0), - baseTraits.getValue().get(1).replace(rightReplace) + baseTraits.getValue().get(1) ) ); } return Pair.of(nodeTraits.replace(RelCollations.EMPTY), - ImmutableList.of(left.replace(RelCollations.EMPTY), right.replace(rightReplace))); + ImmutableList.of(left.replace(RelCollations.EMPTY), right)); Review comment: collation for the right edge should be cleared as well ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteHashIndexSpool.java ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.query.calcite.rel; + +import java.util.List; + +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelOptCost; +import org.apache.calcite.plan.RelOptPlanner; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelInput; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelWriter; +import org.apache.calcite.rel.core.Spool; +import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCost; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCostFactory; +import org.apache.ignite.internal.processors.query.calcite.util.RexUtils; +import org.apache.ignite.internal.util.typedef.F; + +/** + * Relational operator that returns the sorted contents of a table + * and allow to lookup rows by specified bounds. + */ +public class IgniteHashIndexSpool extends Spool implements IgniteRel { + /** Search row. */ + private final List<RexNode> searchRow; + + /** Search row. */ Review comment: wrong comment ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteHashIndexSpool.java ########## @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.query.calcite.rel; + +import java.util.List; + +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelOptCost; +import org.apache.calcite.plan.RelOptPlanner; +import org.apache.calcite.plan.RelTraitSet; +import org.apache.calcite.rel.RelInput; +import org.apache.calcite.rel.RelNode; +import org.apache.calcite.rel.RelWriter; +import org.apache.calcite.rel.core.Spool; +import org.apache.calcite.rel.metadata.RelMetadataQuery; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.util.ImmutableBitSet; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCost; +import org.apache.ignite.internal.processors.query.calcite.metadata.cost.IgniteCostFactory; +import org.apache.ignite.internal.processors.query.calcite.util.RexUtils; +import org.apache.ignite.internal.util.typedef.F; + +/** + * Relational operator that returns the sorted contents of a table + * and allow to lookup rows by specified bounds. + */ +public class IgniteHashIndexSpool extends Spool implements IgniteRel { + /** Search row. */ + private final List<RexNode> searchRow; + + /** Search row. */ + private final ImmutableBitSet keys; + + /** Condition (used to calculate selectivity). */ + private final RexNode cond; + + /** */ + public IgniteHashIndexSpool( + RelOptCluster cluster, + RelTraitSet traits, + RelNode input, + List<RexNode> searchRow, + RexNode cond + ) { + super(cluster, traits, input, Type.LAZY, Type.EAGER); + + assert !F.isEmpty(searchRow); + + this.searchRow = searchRow; + this.cond = cond; + + keys = ImmutableBitSet.of(RexUtils.notNullKeys(searchRow)); + } + + /** + * Constructor used for deserialization. + * + * @param input Serialized representation. + */ + public IgniteHashIndexSpool(RelInput input) { + this(input.getCluster(), + input.getTraitSet().replace(IgniteConvention.INSTANCE), + input.getInputs().get(0), + input.getExpressionList("searchRow"), + null + ); + } + + /** {@inheritDoc} */ + @Override public <T> T accept(IgniteRelVisitor<T> visitor) { + return visitor.visit(this); + } + + /** */ + @Override public IgniteRel clone(RelOptCluster cluster, List<IgniteRel> inputs) { + return new IgniteHashIndexSpool(cluster, getTraitSet(), inputs.get(0), searchRow, cond); + } + + /** {@inheritDoc} */ + @Override protected Spool copy(RelTraitSet traitSet, RelNode input, Type readType, Type writeType) { + return new IgniteHashIndexSpool(getCluster(), traitSet, input, searchRow, cond); + } + + /** {@inheritDoc} */ + @Override public boolean isEnforcer() { + return true; + } + + /** */ + @Override public RelWriter explainTerms(RelWriter pw) { + RelWriter writer = super.explainTerms(pw); + + return writer.item("searchRow", searchRow); + } + + /** {@inheritDoc} */ + @Override public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { + double rowCnt = mq.getRowCount(getInput()); + double bytesPerRow = (getRowType().getFieldCount() - keys.cardinality()) * IgniteCost.AVERAGE_FIELD_SIZE; Review comment: why did you this subtraction? the whole row is stored within the index ########## File path: modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/IgniteCorrelatedNestedLoopJoin.java ########## @@ -138,9 +138,6 @@ public IgniteCorrelatedNestedLoopJoin(RelInput input) { ) { 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 if (variablesSet.size() == 1) { Pair<RelTraitSet, List<RelTraitSet>> baseTraits = super.passThroughCollation(nodeTraits, inputTraits); Review comment: result of the `super` call should be returned as is -- 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]
