Skip to content

Commit 23726b6

Browse files
committed
fix joint hints collection for transitive joins
1 parent f4649fe commit 23726b6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -387,16 +387,14 @@ export class BaseQuery {
387387
}
388388

389389
/**
390-
* Is used by native
391390
* This function follows the same logic as in this.collectJoinHints()
392-
* @private
391+
* @public
393392
* @param {Array<(Array<string> | string)>} hints
394393
* @return {import('../compiler/JoinGraph').FinishedJoinTree}
395394
*/
396395
joinTreeForHints(hints) {
397-
const explicitJoinHintMembers = new Set(hints.filter(j => Array.isArray(j)).flat());
398396
const queryJoinMaps = this.queryJoinMap();
399-
const newCollectedHints = [];
397+
let newCollectedHints = [];
400398

401399
const constructJH = () => R.uniq(this.enrichHintsWithJoinMap([
402400
...newCollectedHints,
@@ -421,8 +419,12 @@ export class BaseQuery {
421419
const iterationCollectedHints = joinMembersJoinHints.filter(j => !allJoinHintsFlatten.has(j));
422420
newJoinHintsCollectedCnt = iterationCollectedHints.length;
423421
cnt++;
424-
if (newJoin) {
425-
newCollectedHints.push(...joinMembersJoinHints.filter(j => !explicitJoinHintMembers.has(j)));
422+
if (newJoin && newJoin.joins.length > 0) {
423+
// Even if there is no join tree changes, we still
424+
// push correctly ordered join hints, collected from the resolving of members of join tree
425+
// upfront the all existing query members. This ensures the correct cube join order
426+
// with transitive joins even if they are already presented among query members.
427+
newCollectedHints = this.enrichedJoinHintsFromJoinTree(newJoin, joinMembersJoinHints);
426428
}
427429
} while (newJoin?.joins.length > 0 && !this.isJoinTreesEqual(prevJoin, newJoin) && cnt < 10000 && newJoinHintsCollectedCnt > 0);
428430

@@ -2694,7 +2696,6 @@ export class BaseQuery {
26942696
*/
26952697
collectJoinHints(excludeTimeDimensions = false) {
26962698
const allMembersJoinHints = this.collectJoinHintsFromMembers(this.allMembersConcat(excludeTimeDimensions));
2697-
const explicitJoinHintMembers = new Set(allMembersJoinHints.filter(j => Array.isArray(j)).flat());
26982699
const queryJoinMaps = this.queryJoinMap();
26992700
const customSubQueryJoinHints = this.collectJoinHintsFromMembers(this.joinMembersFromCustomSubQuery());
27002701
let newCollectedHints = [];

0 commit comments

Comments
 (0)