Jackie-Jiang commented on code in PR #20344:
URL: https://github.com/apache/pinot/pull/20344#discussion_r4673521353
##########
pinot-query-planner/src/main/java/org/apache/pinot/calcite/rel/rules/PinotJoinExchangeNodeInsertRule.java:
##########
@@ -102,7 +108,13 @@ public void onMatch(RelOptRuleCall call) {
}
validateDistributionTypes(leftDistributionType, rightDistributionType,
isReplicatedTableScan(left),
isReplicatedTableScan(right), joinInfo, join.getJoinType());
- newLeft = createExchangeForHashJoin(leftDistributionType,
joinInfo.leftKeys, left, prePartitioned);
+ boolean fuseProbe = join.getJoinType() == JoinRelType.INNER &&
prePartitioned == null
+ && !joinInfo.leftKeys.isEmpty() && joinInfo.isEqui()
+ && leftDistributionType == PinotHintOptions.DistributionType.RANDOM
+ && rightDistributionType ==
PinotHintOptions.DistributionType.BROADCAST
+ && fusionEnabled(call, joinHintOptions) &&
isBroadcastJoinOutput(left);
+ newLeft = fuseProbe ? left
+ : createExchangeForHashJoin(leftDistributionType, joinInfo.leftKeys,
left, prePartitioned);
Review Comment:
[P1] Guard fusion against shared broadcast dependencies
With `useSpools=true`, removing this exchange can create a blocking cycle
for `(f JOIN b) JOIN (d JOIN b)` when both occurrences of `b` are equivalent
broadcast scans. Spool replacement runs after fusion and permits sharing the
producer because its receivers are in different stages. The fused stage fully
builds the outer join's right input before reading its nested left join.
Consequently, it does not drain the nested join's `b` mailbox. Once that
mailbox's five-block queue fills, the shared producer blocks, the right subtree
cannot finish reading `b`, and the fused stage cannot finish building its right
input. The query waits until timeout.
A concrete regression case to add is:
```sql
SET useSpools=true;
SET fuseBroadcastJoins=true;
SELECT /*+ joinOptions(left_distribution_type='random',
right_distribution_type='broadcast') */
f.k, b1.k, r.bk
FROM f
JOIN b b1 ON f.k=b1.k
JOIN (
SELECT /*+ joinOptions(left_distribution_type='random',
right_distribution_type='broadcast') */
d.k, b2.k AS bk
FROM d JOIN b b2 ON d.k=b2.k
) r ON f.k=r.k
```
Use distinct one-column `f` and `d` tables containing only `-1`, and
positive keys in `b` producing more than five streamed blocks. Without fusion,
both lower joins independently drain `b` and emit no rows, so the query
completes empty. With fusion, the dependency above prevents completion. This is
source-traced, not a locally executed reproduction.
Please prevent fusion/spool reuse when it introduces this dependency, or
provide independent buffering/draining for the shared producer, and cover the
case in a runtime test.
##########
pinot-query-planner/src/test/java/org/apache/pinot/query/routing/WorkerManagerTest.java:
##########
@@ -569,6 +570,47 @@ private static void validatePrunableFilter(@Nullable
Expression expression) {
}
}
+ @DataProvider
+ public Object[][] leafFanoutOptions() {
+ return new Object[][]{
+ {"", 1},
+ {"SET leafStageWorkersPerServer=4;", 4},
+ {"SET leafStageWorkersPerServer=16;", 7},
+ {"SET leafStageWorkersPerServer=4; SET multiStageLeafLimit=100;", 1}
+ };
+ }
+
+ @Test(dataProvider = "leafFanoutOptions")
+ public void testOptInFanoutWithFusedBroadcastJoins(String options, int
factWorkers) {
+ Schema schema = getSchemaBuilder("testTable").build();
+ ServerInstance server = getServerInstance("localhost", 1);
+ List<String> segments = IntStream.range(0,
7).mapToObj(Integer::toString).toList();
+ RoutingTable routing = new RoutingTable(Map.of(server, new
SegmentsToQuery(segments, List.of())), List.of(), 0);
+ QueryEnvironment env = newQueryEnvironment(schema,
+ new CapturingRoutingManager(Map.of(server.getInstanceId(), server),
Map.of("testTable_OFFLINE", routing)));
+ String query = options + " SET fuseBroadcastJoins=true; "
+ + "SELECT /*+
joinOptions(left_distribution_type='random',right_distribution_type='broadcast')
*/ "
+ + "f.col3,c.col2,p.col2 FROM testTable f JOIN testTable c ON
f.col1=c.col1 "
+ + "JOIN testTable p ON f.col2=p.col2";
+ try (QueryEnvironment.CompiledQuery compiled = env.compile(query)) {
+ DispatchableSubPlan subPlan = compiled.planQuery(0).getQueryPlan();
Review Comment:
[P2] Exercise leaf fanout through query execution
This test stops at planner assignments, so it cannot validate the new path
through dispatch, per-worker leaf request construction, and execution. No
execution test sets `leafStageWorkersPerServer`: the new `QueryRunnerTest`
enables only fusion and uses a realtime fact table, while
`ServerPlanRequestUtilsTest` checks only request-ID arithmetic.
Please add a runtime query test with seven real OFFLINE segments on one
server, worker settings `1`, `4`, and `16`, and fusion on/off. Assert that
fanout actually occurs and that the resulting rows, counts, and sums match the
single-worker/reference result.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]