You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "Vladsz83 (via GitHub)" <gi...@apache.org> on 2025/04/01 13:51:07 UTC
[PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Vladsz83 opened a new pull request, #11977:
URL: https://github.com/apache/ignite/pull/11977
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
### The Contribution Checklist
- [ ] There is a single JIRA ticket related to the pull request.
- [ ] The web-link to the pull request is attached to the JIRA ticket.
- [ ] The JIRA ticket has the _Patch Available_ state.
- [ ] The pull request body describes changes that have been made.
The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
- [ ] The pull request title is treated as the final commit message.
The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
- [ ] A reviewer has been mentioned through the JIRA comments
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers))
- [ ] The pull request has been checked by the Teamcity Bot and
the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #11977:
URL: https://github.com/apache/ignite/pull/11977#issuecomment-3116556819
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11977) **Quality Gate failed**
Failed conditions
 [7 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11977) (required ≤ 1)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11977)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11977:
URL: https://github.com/apache/ignite/pull/11977#discussion_r2205344921
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -1020,13 +959,17 @@ else if (cmp > 0) {
}
/** */
- private static class SemiJoin<Row> extends MergeJoinNode<Row> {
- /** */
- private Row left;
+ protected void tryToRequestInputs() throws Exception {
+ // Check `requested` to avoid endless buffer filling while unable to cycle.
+ if (waitingLeft == 0 && requested > 0)
Review Comment:
Can't reproduce
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11977:
URL: https://github.com/apache/ignite/pull/11977#discussion_r2097629960
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -1020,13 +959,17 @@ else if (cmp > 0) {
}
/** */
- private static class SemiJoin<Row> extends MergeJoinNode<Row> {
- /** */
- private Row left;
+ protected void tryToRequestInputs() throws Exception {
+ // Check `requested` to avoid endless buffer filling while unable to cycle.
+ if (waitingLeft == 0 && requested > 0)
Review Comment:
Still can overflow buffers. Can be reproduced with execution test:
```
@Test
public void testJoinBuffers() throws Exception {
ExecutionContext<Object[]> ctx = executionContext(F.first(nodes()), UUID.randomUUID(), 0);
Iterator<Object[]> leftIter = IntStream.range(0, 1_000_000).boxed().map(i -> new Object[] {i}).iterator();
Iterator<Object[]> rightIter = IntStream.range(1_000_000, 2_000_000).boxed().map(i -> new Object[] {i}).iterator();
RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class);
ScanNode<Object[]> leftNode = new ScanNode<>(ctx, leftType, () -> leftIter);
RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class);
ScanNode<Object[]> rightNode = new ScanNode<>(ctx, rightType, () -> rightIter);
RelDataType outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, int.class);
MergeJoinNode<Object[]> join = MergeJoinNode.create(ctx, outType, leftType, rightType, INNER,
Comparator.comparingInt(r -> (Integer)r[0]), false);
join.register(F.asList(leftNode, rightNode));
List<Object[]> res = new ArrayList<>();
join.onRegister(new Downstream<>() {
@Override public void push(Object[] objects) {
res.add(objects);
}
@Override public void end() {
// No-op.
}
@Override public void onError(Throwable e) {
// No-op.
}
});
join.request(1);
doSleep(1_000L);
assertTrue(join.leftInBuf.size() <= IN_BUFFER_SIZE);
assertTrue(join.rightInBuf.size() <= IN_BUFFER_SIZE);
}
```
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11977:
URL: https://github.com/apache/ignite/pull/11977#discussion_r2213569010
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -1006,27 +942,24 @@ else if (cmp > 0) {
inLoop = false;
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
+ if (requested > 0 && leftFinished() && rightFinished(true) && checkJoinFinished())
+ return;
- if (waitingLeft == 0)
- leftSource().request(waitingLeft = IN_BUFFER_SIZE);
-
- if (requested > 0 && waitingLeft == NOT_WAITING && left == null && leftInBuf.isEmpty()
- && waitingRight == NOT_WAITING && right == null && rightInBuf.isEmpty() && rightMaterialization == null
- )
- checkJoinFinished();
+ tryToRequestInputs();
}
}
/** */
- private static class SemiJoin<Row> extends MergeJoinNode<Row> {
- /** */
- private Row left;
+ protected void tryToRequestInputs() throws Exception {
Review Comment:
Move before or after all join classes
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11977:
URL: https://github.com/apache/ignite/pull/11977#discussion_r2097629960
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -1020,13 +959,17 @@ else if (cmp > 0) {
}
/** */
- private static class SemiJoin<Row> extends MergeJoinNode<Row> {
- /** */
- private Row left;
+ protected void tryToRequestInputs() throws Exception {
+ // Check `requested` to avoid endless buffer filling while unable to cycle.
+ if (waitingLeft == 0 && requested > 0)
Review Comment:
Still can overflow buffers. Can be reproduced with execution test:
```
@Test
public void testJoinBuffers() throws Exception {
ExecutionContext<Object[]> ctx = executionContext(F.first(nodes()), UUID.randomUUID(), 0);
Iterator<Object[]> leftIter = IntStream.range(0, 1_000_000).boxed().map(i -> new Object[] {i}).iterator();
Iterator<Object[]> rightIter = IntStream.range(1_000_000, 2_000_000).boxed().map(i -> new Object[] {i}).iterator();
RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class);
ScanNode<Object[]> leftNode = new ScanNode<>(ctx, leftType, () -> leftIter);
RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class);
ScanNode<Object[]> rightNode = new ScanNode<>(ctx, rightType, () -> rightIter);
RelDataType outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, int.class);
MergeJoinNode<Object[]> join = MergeJoinNode.create(ctx, outType, leftType, rightType, INNER,
Comparator.comparingInt(r -> (Integer)r[0]), true);
join.register(F.asList(leftNode, rightNode));
List<Object[]> res = new ArrayList<>();
AtomicBoolean finished = new AtomicBoolean();
join.onRegister(new Downstream<>() {
@Override public void push(Object[] objects) {
res.add(objects);
}
@Override public void end() {
finished.set(true);
}
@Override public void onError(Throwable e) {
// No-op.
}
});
join.request(1);
assertTrue(GridTestUtils.waitForCondition(finished::get, 5_000L));
assertTrue(join.leftInBuf.size() <= IN_BUFFER_SIZE);
assertTrue(join.rightInBuf.size() <= IN_BUFFER_SIZE);
}
```
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11977:
URL: https://github.com/apache/ignite/pull/11977#discussion_r2194461837
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/AbstractJoinExecutionTest.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.rel;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.util.TypeUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.calcite.rel.core.JoinRelType.ANTI;
+import static org.apache.calcite.rel.core.JoinRelType.FULL;
+import static org.apache.calcite.rel.core.JoinRelType.INNER;
+import static org.apache.calcite.rel.core.JoinRelType.LEFT;
+import static org.apache.calcite.rel.core.JoinRelType.RIGHT;
+import static org.apache.calcite.rel.core.JoinRelType.SEMI;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+abstract class AbstractJoinExecutionTest extends AbstractExecutionTest {
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract JoinCreator joinCreator();
+
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract Consumer<AbstractNode<?>> joinFinalChecker();
+
+ /** Tests join of certain type with input bigger that the buffer size. */
+ @Test
+ public void testJoinBufer() throws Exception {
+ for (JoinRelType joinType : F.asList(LEFT, INNER, RIGHT, FULL, SEMI, ANTI)) {
+ if (log.isInfoEnabled())
+ log.info("Testing join of type '" + joinType + "'...");
+
+ doTestJoinBuffer(joinType, joinCreator(), joinFinalChecker());
+ }
+ }
+
+ /**
+ * @param jType Join type.
+ * @param jCreator Creates certain join node.
+ * @param finalChecker Finally check node after successfull run
+ */
+ private void doTestJoinBuffer(JoinRelType jType, JoinCreator jCreator, Consumer<AbstractNode<?>> finalChecker) throws Exception {
+ int size = IN_BUFFER_SIZE * 2 + IN_BUFFER_SIZE / 2;
+ int intersect = Math.max(10, IN_BUFFER_SIZE / 10);
+
+ int leftTo = size + intersect;
+ int rightTo = size * 2;
+
+ ExecutionContext<Object[]> ctx = executionContext(F.first(nodes()), UUID.randomUUID(), 0);
+
+ Iterator<Object[]> leftIter = IntStream.range(0, leftTo).boxed().map(i -> new Object[] {i}).iterator();
+ Iterator<Object[]> rightIter = IntStream.range(size, rightTo).boxed().map(i -> new Object[] {i}).iterator();
+
+ RelDataType leftType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class);
+ ScanNode<Object[]> leftNode = new ScanNode<>(ctx, leftType, () -> leftIter);
+
+ RelDataType rightType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class);
+ ScanNode<Object[]> rightNode = new ScanNode<>(ctx, rightType, () -> rightIter);
+
+ RelDataType outType = TypeUtils.createRowType(ctx.getTypeFactory(), int.class, int.class);
+
+ AbstractNode<Object[]> join = jCreator.create(ctx, outType, leftType, rightType, jType,
+ (r1, r2) -> r1[0].equals(r2[0]));
+
+ join.register(F.asList(leftNode, rightNode));
+
+ List<Object[]> res = new ArrayList<>();
+ AtomicBoolean finished = new AtomicBoolean();
+
+ join.onRegister(new Downstream<>() {
+ @Override public void push(Object[] objects) {
+ res.add(objects);
+ }
+
+ @Override public void end() {
+ finished.set(true);
+ }
+
+ @Override public void onError(Throwable e) {
+ // No-op.
+ }
+ });
+
Review Comment:
Let's also check intermidiate result without `Downstream.end()` here:
```
join.request(1);
assertTrue(GridTestUtils.waitForCondition(() -> !res.isEmpty(), getTestTimeout()));
bufChecker.accept(join);
```
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -151,7 +165,8 @@ private void pushLeft(Row row) throws Exception {
leftInBuf.add(row);
- join();
+ if (waitingLeft <= 0)
Review Comment:
Can delay rows output (see comment for merge join)
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -809,16 +710,41 @@ public AntiJoin(ExecutionContext<Row> ctx, RelDataType rowType, BiPredicate<Row,
}
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
+ tryGetMoreOrEnd();
+ }
+ }
- if (waitingLeft == 0 && leftInBuf.isEmpty())
- leftSource().request(waitingLeft = IN_BUFFER_SIZE);
+ /** */
+ protected void tryGetMoreOrEnd(@Nullable Supplier<Boolean> extCheck) throws Exception {
+ if (requested > 0 && waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING && left == null && leftInBuf.isEmpty()
+ && (extCheck == null || extCheck.get())
+ ) {
+ requested = 0;
+ rightMaterialized.clear();
- if (requested > 0 && waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING && left == null && leftInBuf.isEmpty()) {
- requested = 0;
- downstream().end();
- }
+ downstream().end();
+
+ return;
}
+
+ if (waitingLeft == 0 && requested > 0 && leftInBuf.size() <= HALF_BUF_SIZE)
+ leftSource().request(waitingLeft = IN_BUFFER_SIZE - leftInBuf.size());
+
+ if (waitingRight == 0 && requested > 0 && rightMaterialized.size() <= HALF_BUF_SIZE)
Review Comment:
Incorrect condition, rightMaterialized should not be limited
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/tpch/AbstractTpchTest.java:
##########
@@ -26,15 +26,21 @@
/** */
@RunWith(Parameterized.class)
-public class TpchTest extends AbstractBasicIntegrationTest {
+public abstract class AbstractTpchTest extends AbstractBasicIntegrationTest {
+ /** */
+ protected static final Collection<Integer> USED_TESTS = F.asList(17, 19, 20);
+
/** Query ID. */
@Parameterized.Parameter
public int qryId;
+ /** */
+ protected abstract double scale();
+
/** */
@Parameterized.Parameters(name = "queryId={0}")
- public static Collection<Object> params() {
- return F.asList(16, 19, 20);
Review Comment:
Why 16 is removed?
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -673,28 +622,12 @@ public FullOuterJoin(
}
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
-
- if (waitingLeft == 0 && leftInBuf.isEmpty())
- leftSource().request(waitingLeft = IN_BUFFER_SIZE);
-
- if (requested > 0 && waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING && left == null
- && leftInBuf.isEmpty() && rightNotMatchedIndexes.isEmpty()) {
- requested = 0;
- downstream().end();
- }
+ tryGetMoreOrEnd(() -> rightNotMatchedIndexes.isEmpty());
Review Comment:
Let's simplify to something:
```
if (rightNotMatchedIndexes.isEmpty() && checkJoinFinished())
return;
tryToRequestInputs();
```
(WIll look similar to merge join and simplier to read)
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/AbstractJoinExecutionTest.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.rel;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.util.TypeUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.calcite.rel.core.JoinRelType.ANTI;
+import static org.apache.calcite.rel.core.JoinRelType.FULL;
+import static org.apache.calcite.rel.core.JoinRelType.INNER;
+import static org.apache.calcite.rel.core.JoinRelType.LEFT;
+import static org.apache.calcite.rel.core.JoinRelType.RIGHT;
+import static org.apache.calcite.rel.core.JoinRelType.SEMI;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+abstract class AbstractJoinExecutionTest extends AbstractExecutionTest {
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract JoinCreator joinCreator();
+
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract Consumer<AbstractNode<?>> joinFinalChecker();
+
+ /** Tests join of certain type with input bigger that the buffer size. */
+ @Test
+ public void testJoinBufer() throws Exception {
+ for (JoinRelType joinType : F.asList(LEFT, INNER, RIGHT, FULL, SEMI, ANTI)) {
+ if (log.isInfoEnabled())
+ log.info("Testing join of type '" + joinType + "'...");
+
+ doTestJoinBuffer(joinType, joinCreator(), joinFinalChecker());
+ }
+ }
+
+ /**
+ * @param jType Join type.
+ * @param jCreator Creates certain join node.
+ * @param finalChecker Finally check node after successfull run
+ */
+ private void doTestJoinBuffer(JoinRelType jType, JoinCreator jCreator, Consumer<AbstractNode<?>> finalChecker) throws Exception {
Review Comment:
'j' is not a common abbreviation for 'join', let's use 'join' in variable names
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/AbstractJoinExecutionTest.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.rel;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.util.TypeUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.calcite.rel.core.JoinRelType.ANTI;
+import static org.apache.calcite.rel.core.JoinRelType.FULL;
+import static org.apache.calcite.rel.core.JoinRelType.INNER;
+import static org.apache.calcite.rel.core.JoinRelType.LEFT;
+import static org.apache.calcite.rel.core.JoinRelType.RIGHT;
+import static org.apache.calcite.rel.core.JoinRelType.SEMI;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+abstract class AbstractJoinExecutionTest extends AbstractExecutionTest {
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract JoinCreator joinCreator();
+
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract Consumer<AbstractNode<?>> joinFinalChecker();
+
+ /** Tests join of certain type with input bigger that the buffer size. */
+ @Test
+ public void testJoinBufer() throws Exception {
+ for (JoinRelType joinType : F.asList(LEFT, INNER, RIGHT, FULL, SEMI, ANTI)) {
+ if (log.isInfoEnabled())
+ log.info("Testing join of type '" + joinType + "'...");
+
+ doTestJoinBuffer(joinType, joinCreator(), joinFinalChecker());
+ }
+ }
+
+ /**
+ * @param jType Join type.
+ * @param jCreator Creates certain join node.
+ * @param finalChecker Finally check node after successfull run
Review Comment:
point at the EOL
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -213,12 +242,33 @@ protected Node<Row> rightSource() {
/** */
protected abstract void join() throws Exception;
- /** */
- protected void checkJoinFinished() throws Exception {
- if (!distributed || (waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING)) {
+ /** Checks if finished considering strictly one shoulder. */
+ protected boolean checkFinished(boolean leftShoulder) throws Exception {
+ return checkFinished(leftShoulder ? -1 : 1, false);
+ }
+
+ /**
+ * Checks if finished. Can take in account one or both shoulders.
+ *
+ * @param shoulder If <0, checks the only left input. If is 0, checks both inputs. If >0, checks only right input.
+ * @param strict Works with only with {@code input} == 0. If {@code true}, checks both inputs. Otherwise, checks any input.
+ */
+ protected boolean checkFinished(int shoulder, boolean strict) throws Exception {
Review Comment:
- Overcomplicated API (hard to understand what is really checked)
- Inconsistent API (boolean in one method, integer in another method)
- Condition in checkFinished fully covered by condition of each join, except "!distributed", so effectively can be removed.
- I've proposed the patch earlier, to reduce buffer changes for distributed join (we need to drain remote sources but no need to store and join data):
```
if (!finishing) {
finishing = true;
leftInBuf.clear();
rightInBuf.clear();
}
```
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -213,12 +242,33 @@ protected Node<Row> rightSource() {
/** */
protected abstract void join() throws Exception;
- /** */
- protected void checkJoinFinished() throws Exception {
- if (!distributed || (waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING)) {
+ /** Checks if finished considering strictly one shoulder. */
+ protected boolean checkFinished(boolean leftShoulder) throws Exception {
Review Comment:
For joins usually used word 'hand', not 'shoulder'
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -809,16 +710,41 @@ public AntiJoin(ExecutionContext<Row> ctx, RelDataType rowType, BiPredicate<Row,
}
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
+ tryGetMoreOrEnd();
+ }
+ }
- if (waitingLeft == 0 && leftInBuf.isEmpty())
- leftSource().request(waitingLeft = IN_BUFFER_SIZE);
+ /** */
+ protected void tryGetMoreOrEnd(@Nullable Supplier<Boolean> extCheck) throws Exception {
+ if (requested > 0 && waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING && left == null && leftInBuf.isEmpty()
+ && (extCheck == null || extCheck.get())
+ ) {
+ requested = 0;
+ rightMaterialized.clear();
- if (requested > 0 && waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING && left == null && leftInBuf.isEmpty()) {
- requested = 0;
- downstream().end();
- }
+ downstream().end();
+
+ return;
}
+
+ if (waitingLeft == 0 && requested > 0 && leftInBuf.size() <= HALF_BUF_SIZE)
Review Comment:
See comment about `requested > 0` for merge join
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/AbstractJoinExecutionTest.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.rel;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.util.TypeUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.calcite.rel.core.JoinRelType.ANTI;
+import static org.apache.calcite.rel.core.JoinRelType.FULL;
+import static org.apache.calcite.rel.core.JoinRelType.INNER;
+import static org.apache.calcite.rel.core.JoinRelType.LEFT;
+import static org.apache.calcite.rel.core.JoinRelType.RIGHT;
+import static org.apache.calcite.rel.core.JoinRelType.SEMI;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+abstract class AbstractJoinExecutionTest extends AbstractExecutionTest {
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract JoinCreator joinCreator();
+
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract Consumer<AbstractNode<?>> joinFinalChecker();
Review Comment:
It looks not very consistent. These methods required only for one test (with parameters related only to this test), but redefined for children classes. Maybe it's better to have dedicated test class to check buffers with parameters for MERGE and NL join? Also JoinCreator interface and Consumer for buffer checker are redundant, you can use methods like `createJoin` and `checkBuffers` without additional wrapping.
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/AbstractJoinExecutionTest.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.rel;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext;
+import org.apache.ignite.internal.processors.query.calcite.util.TypeUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.calcite.rel.core.JoinRelType.ANTI;
+import static org.apache.calcite.rel.core.JoinRelType.FULL;
+import static org.apache.calcite.rel.core.JoinRelType.INNER;
+import static org.apache.calcite.rel.core.JoinRelType.LEFT;
+import static org.apache.calcite.rel.core.JoinRelType.RIGHT;
+import static org.apache.calcite.rel.core.JoinRelType.SEMI;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+abstract class AbstractJoinExecutionTest extends AbstractExecutionTest {
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract JoinCreator joinCreator();
+
+ /** @see #doTestJoinBuffer(JoinRelType, JoinCreator, Consumer) */
+ protected abstract Consumer<AbstractNode<?>> joinFinalChecker();
+
+ /** Tests join of certain type with input bigger that the buffer size. */
+ @Test
+ public void testJoinBufer() throws Exception {
+ for (JoinRelType joinType : F.asList(LEFT, INNER, RIGHT, FULL, SEMI, ANTI)) {
+ if (log.isInfoEnabled())
+ log.info("Testing join of type '" + joinType + "'...");
+
+ doTestJoinBuffer(joinType, joinCreator(), joinFinalChecker());
Review Comment:
joinCreator -> joinFactory
joinFinalChecker -> joinBufChecker (final checker sounds like it checks the final result)
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -1006,27 +943,27 @@ else if (cmp > 0) {
inLoop = false;
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
-
- if (waitingLeft == 0)
- leftSource().request(waitingLeft = IN_BUFFER_SIZE);
-
if (requested > 0 && waitingLeft == NOT_WAITING && left == null && leftInBuf.isEmpty()
&& waitingRight == NOT_WAITING && right == null && rightInBuf.isEmpty() && rightMaterialization == null
+ && checkFinished(0, true)
)
- checkJoinFinished();
+ return;
+
+ tryToRequestInputs();
}
}
/** */
- private static class SemiJoin<Row> extends MergeJoinNode<Row> {
- /** */
- private Row left;
+ protected void tryToRequestInputs() throws Exception {
+ if (waitingLeft == 0 && requested > 0 && leftInBuf.size() <= HALF_BUF_SIZE)
Review Comment:
Why do we need `requested > 0` here? Condition with `leftInBuf.size()` already covers all problems related to buffer overflow. Any tests that can prove that additional condition is required? IMO this condition can add another problems (for example, we need to drain remote sources even if requested is 0).
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -159,7 +184,8 @@ private void pushLeft(Row row) throws Exception {
leftInBuf.add(row);
- join();
+ if (waitingLeft == 0 && waitingRight <= 0)
Review Comment:
These conditions will delay rows output and will increase request latancy. Also, when we need only one row (CNLJ) we will wait for the whole right and left batches before row will be produced.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11977:
URL: https://github.com/apache/ignite/pull/11977#discussion_r2212859928
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -772,14 +737,13 @@ else if (cmp > 0) {
inLoop = false;
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
+ if (requested > 0 && rightFinished(true) && (!distributed || waitingRight == NOT_WAITING)) {
Review Comment:
Not correct condition, for distributed join both hands should be drained
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -523,17 +493,10 @@ public RightJoin(
}
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
-
- if (waitingLeft == 0 && leftInBuf.isEmpty())
- leftSource().request(waitingLeft = IN_BUFFER_SIZE);
+ if ((rightNotMatchedIndexes == null || rightNotMatchedIndexes.isEmpty()) && checkJoinFinished())
Review Comment:
F.isEmpty(rightNotMatchedIndexes)
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/MergeJoinNode.java:
##########
@@ -213,12 +242,33 @@ protected Node<Row> rightSource() {
/** */
protected abstract void join() throws Exception;
- /** */
- protected void checkJoinFinished() throws Exception {
- if (!distributed || (waitingLeft == NOT_WAITING && waitingRight == NOT_WAITING)) {
+ /** Checks if finished considering strictly one shoulder. */
+ protected boolean checkFinished(boolean leftShoulder) throws Exception {
+ return checkFinished(leftShoulder ? -1 : 1, false);
+ }
+
+ /**
+ * Checks if finished. Can take in account one or both shoulders.
+ *
+ * @param shoulder If <0, checks the only left input. If is 0, checks both inputs. If >0, checks only right input.
+ * @param strict Works with only with {@code input} == 0. If {@code true}, checks both inputs. Otherwise, checks any input.
+ */
+ protected boolean checkFinished(int shoulder, boolean strict) throws Exception {
Review Comment:
Last item still not fixed
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11977:
URL: https://github.com/apache/ignite/pull/11977#discussion_r2213162591
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/NestedLoopJoinNode.java:
##########
@@ -523,17 +493,10 @@ public RightJoin(
}
}
- if (waitingRight == 0)
- rightSource().request(waitingRight = IN_BUFFER_SIZE);
-
- if (waitingLeft == 0 && leftInBuf.isEmpty())
- leftSource().request(waitingLeft = IN_BUFFER_SIZE);
+ if ((rightNotMatchedIndexes == null || rightNotMatchedIndexes.isEmpty()) && checkJoinFinished())
Review Comment:
There is no method for a `BitSet`. Not sure we should add for this simple case.
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-24754 : query #17 possible require too much heap [ignite]
Posted by "asf-gitbox-commits (via GitHub)" <gi...@apache.org>.
asf-gitbox-commits closed pull request #11977: IGNITE-24754 : query #17 possible require too much heap
URL: https://github.com/apache/ignite/pull/11977
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org