This is an automated email from the ASF dual-hosted git repository.
korlov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new e2140a4bcd4 IGNITE-24678 Sql. Introduce heuristic to exclude NLJ when
HJ may be applied (#5322)
e2140a4bcd4 is described below
commit e2140a4bcd490e01489b3977878f88de0d555e1d
Author: korlov42 <[email protected]>
AuthorDate: Thu Mar 6 14:48:37 2025 +0200
IGNITE-24678 Sql. Introduce heuristic to exclude NLJ when HJ may be applied
(#5322)
---
.../src/integrationTest/sql/group2/sqlite/join/join1.test | 2 ++
.../internal/sql/engine/rule/HashJoinConverterRule.java | 11 ++++++++---
.../internal/sql/engine/rule/NestedLoopJoinConverterRule.java | 6 ++++++
modules/sql-engine/src/test/resources/tpch/plan/q5.plan | 2 +-
modules/sql-engine/src/test/resources/tpch/plan/q8.plan | 2 +-
5 files changed, 18 insertions(+), 5 deletions(-)
diff --git
a/modules/sql-engine/src/integrationTest/sql/group2/sqlite/join/join1.test
b/modules/sql-engine/src/integrationTest/sql/group2/sqlite/join/join1.test
index cbf6fa4f7be..d7a05392287 100644
--- a/modules/sql-engine/src/integrationTest/sql/group2/sqlite/join/join1.test
+++ b/modules/sql-engine/src/integrationTest/sql/group2/sqlite/join/join1.test
@@ -108,6 +108,8 @@ INSERT INTO t3 VALUES(3,4,5);
statement ok
INSERT INTO t3 VALUES(4,5,6);
+skipif ignite3
+# Ignore https://issues.apache.org/jira/browse/IGNITE-24716
query IIIII nosort
SELECT t1.c, t2.d, t1.b, t1.a, t3.e FROM t1 natural join t2 natural join t3
WHERE t1.a=1;
----
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/HashJoinConverterRule.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/HashJoinConverterRule.java
index 30b32009f48..7d760549ebd 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/HashJoinConverterRule.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/HashJoinConverterRule.java
@@ -57,13 +57,18 @@ public class HashJoinConverterRule extends
AbstractIgniteConverterRule<LogicalJo
public boolean matches(RelOptRuleCall call) {
LogicalJoin logicalJoin = call.rel(0);
- if (nullOrEmpty(logicalJoin.analyzeCondition().pairs())) {
+ return matches(logicalJoin);
+ }
+
+ /** Returns {@code true} if this rule can be applied to given join node,
returns {@code false} otherwise. */
+ public static boolean matches(LogicalJoin join) {
+ if (nullOrEmpty(join.analyzeCondition().pairs())) {
return false;
}
List<Boolean> filterNulls = new ArrayList<>();
RelOptUtil.splitJoinCondition(
- logicalJoin.getLeft(), logicalJoin.getRight(),
logicalJoin.getCondition(),
+ join.getLeft(), join.getRight(), join.getCondition(),
new ArrayList<>(), new ArrayList<>(), filterNulls
);
@@ -73,7 +78,7 @@ public class HashJoinConverterRule extends
AbstractIgniteConverterRule<LogicalJo
}
//noinspection RedundantIfStatement
- if (!logicalJoin.analyzeCondition().isEqui() &&
!TYPES_SUPPORTING_NON_EQUI_CONDITIONS.contains(logicalJoin.getJoinType())) {
+ if (!join.analyzeCondition().isEqui() &&
!TYPES_SUPPORTING_NON_EQUI_CONDITIONS.contains(join.getJoinType())) {
// Joins which emits unmatched left or right part requires special
handling of `nonEquiCondition`
// on execution level. As of now it's known limitations.
return false;
diff --git
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/NestedLoopJoinConverterRule.java
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/NestedLoopJoinConverterRule.java
index 0c216bc8825..a066cd4a53f 100644
---
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/NestedLoopJoinConverterRule.java
+++
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/NestedLoopJoinConverterRule.java
@@ -45,6 +45,12 @@ public class NestedLoopJoinConverterRule extends
AbstractIgniteConverterRule<Log
/** {@inheritDoc} */
@Override
protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq,
LogicalJoin rel) {
+ boolean hasHashJoinRule =
planner.getRules().contains(HashJoinConverterRule.INSTANCE);
+
+ if (hasHashJoinRule && HashJoinConverterRule.matches(rel)) {
+ return null;
+ }
+
RelOptCluster cluster = rel.getCluster();
RelTraitSet traits = cluster.traitSetOf(IgniteConvention.INSTANCE)
.replace(IgniteDistributions.single());
diff --git a/modules/sql-engine/src/test/resources/tpch/plan/q5.plan
b/modules/sql-engine/src/test/resources/tpch/plan/q5.plan
index d10d12941a9..799dfa255c9 100644
--- a/modules/sql-engine/src/test/resources/tpch/plan/q5.plan
+++ b/modules/sql-engine/src/test/resources/tpch/plan/q5.plan
@@ -54,7 +54,7 @@ Sort
table: [PUBLIC, SUPPLIER]
fields: [S_SUPPKEY, S_NATIONKEY]
est. row count: 10000
- NestedLoopJoin
+ HashJoin
condition: =(N_REGIONKEY, R_REGIONKEY)
joinType: inner
est. row count: 8
diff --git a/modules/sql-engine/src/test/resources/tpch/plan/q8.plan
b/modules/sql-engine/src/test/resources/tpch/plan/q8.plan
index 87a1415007c..29d5503f6ea 100644
--- a/modules/sql-engine/src/test/resources/tpch/plan/q8.plan
+++ b/modules/sql-engine/src/test/resources/tpch/plan/q8.plan
@@ -55,7 +55,7 @@ Sort
table: [PUBLIC, CUSTOMER]
fields: [C_CUSTKEY, C_NATIONKEY]
est. row count: 150000
- NestedLoopJoin
+ HashJoin
condition: =(N_REGIONKEY, R_REGIONKEY)
joinType: inner
est. row count: 8