Skip to content

Commit 601c4ff

Browse files
IGNITE-24721 SQL Calcite: Fix distribution for rehashing to the right hand of JOIN - Fixes #11913.
Signed-off-by: Aleksey Plekhanov <plehanov.alex@gmail.com>
1 parent dee59bf commit 601c4ff

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/rel/AbstractIgniteJoin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected AbstractIgniteJoin(RelOptCluster cluster, RelTraitSet traitSet, RelNod
174174
}
175175

176176
if (rightDistr.getType() == HASH_DISTRIBUTED && right2leftProjectedDistr != random()) {
177-
outTraits = nodeTraits.replace(rightDistr);
177+
outTraits = nodeTraits.replace(right2leftProjectedDistr);
178178
leftTraits = left.replace(right2leftProjectedDistr);
179179
rightTraits = right.replace(rightDistr);
180180

modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/JoinRehashIntegrationTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void testNullAffinityKeys() {
6060

6161
// Add null values.
6262
for (int i = 0; i < 10; i++)
63-
sql("INSERT INTO order_items VALUES(?, null, null, null)", "null_key_" + i);
63+
sql("INSERT INTO order_items (id) VALUES(?)", "null_key_" + i);
6464

6565
String sql = "SELECT sum(i.price * i.amount)" +
6666
" FROM order_items i JOIN orders o ON o.id=i.orderId" +
@@ -73,11 +73,31 @@ public void testNullAffinityKeys() {
7373
.check();
7474
}
7575

76+
/** */
77+
@Test
78+
public void testRehashOnRightHand() {
79+
prepareTables();
80+
81+
assertQuery("SELECT /*+ ENFORCE_JOIN_ORDER */ o.id, i.id " +
82+
"FROM order_items oi JOIN items i ON (i.id = oi.itemId) JOIN orders o ON (oi.orderId = o.id) " +
83+
"WHERE oi.orderId between 2 and 3 and oi.itemId between 4 and 5")
84+
.matches(QueryChecker.containsSubPlan("IgniteExchange(distribution=[affinity"))
85+
.returns(2, 4).returns(2, 5).returns(3, 4).returns(3, 5)
86+
.check();
87+
}
88+
7689
/** Prepare tables orders and order_items with data. */
7790
private void prepareTables() {
91+
sql("CREATE TABLE items (\n" +
92+
" id int,\n" +
93+
" name varchar,\n" +
94+
" PRIMARY KEY (id))\n" +
95+
" WITH \"cache_name=items,backups=1," + atomicity() + "\"");
96+
7897
sql("CREATE TABLE order_items (\n" +
7998
" id varchar,\n" +
8099
" orderId int,\n" +
100+
" itemId int,\n" +
81101
" price decimal,\n" +
82102
" amount int,\n" +
83103
" PRIMARY KEY (id))\n" +
@@ -90,12 +110,16 @@ private void prepareTables() {
90110
" WITH \"cache_name=orders,backups=1," + atomicity() + "\"");
91111

92112
sql("CREATE INDEX order_items_orderId ON order_items (orderId ASC)");
113+
sql("CREATE INDEX order_items_itemId ON order_items (itemId ASC)");
93114
sql("CREATE INDEX orders_region ON orders (region ASC)");
94115

116+
for (int i = 0; i < 20; i++)
117+
sql("INSERT INTO items VALUES(?, ?)", i, "item" + i);
118+
95119
for (int i = 0; i < 30; i++) {
96120
sql("INSERT INTO orders VALUES(?, ?)", i, "region" + i % 10);
97121
for (int j = 0; j < 20; j++)
98-
sql("INSERT INTO order_items VALUES(?, ?, ?, ?)", i + "_" + j, i, i / 10.0, j % 10);
122+
sql("INSERT INTO order_items VALUES(?, ?, ?, ?, ?)", i + "_" + j, i, j, i / 10.0, j % 10);
99123
}
100124
}
101125
}

0 commit comments

Comments
 (0)