@@ -418,40 +418,38 @@ export class BaseQuery {
418
418
get allJoinHints ( ) {
419
419
if ( ! this . collectedJoinHints ) {
420
420
// this.collectedJoinHints = this.collectJoinHints();
421
- const allMembersJoinHints = this . collectJoinHintsFromMembers ( this . allMembersConcat ( false ) ) ;
421
+ const [ rootOfJoin , ... allMembersJoinHints ] = this . collectJoinHintsFromMembers ( this . allMembersConcat ( false ) ) ;
422
422
const customSubQueryJoinHints = this . collectJoinHintsFromMembers ( this . joinMembersFromCustomSubQuery ( ) ) ;
423
423
let joinMembersJoinHints = this . collectJoinHintsFromMembers ( this . joinMembersFromJoin ( ) ) ;
424
424
425
425
// One cube may join the other cube via transitive joined cubes,
426
426
// members from which are referenced in the join `on` clauses.
427
- // We need to collect such join hints and push them upfront of the joining one.
427
+ // We need to collect such join hints and push them upfront of the joining one
428
+ // but only if they don't exist yet. Cause in other case we might affect what
429
+ // join path will be constructed in join graph.
428
430
// It is important to use queryLevelJoinHints during the calculation if it is set.
429
431
432
+ const constructJP = ( ) => {
433
+ const filteredJoinMembersJoinHints = joinMembersJoinHints . filter ( m => ! allMembersJoinHints . includes ( m ) ) ;
434
+ return [
435
+ ...this . queryLevelJoinHints ,
436
+ rootOfJoin ,
437
+ ...filteredJoinMembersJoinHints ,
438
+ ...allMembersJoinHints ,
439
+ ...customSubQueryJoinHints ,
440
+ ] ;
441
+ } ;
442
+
430
443
const prevJoins = this . join ;
431
444
432
- let newJoin = this . joinGraph . buildJoin ( [
433
- ...this . queryLevelJoinHints ,
434
- ...allMembersJoinHints ,
435
- ...joinMembersJoinHints ,
436
- ...customSubQueryJoinHints ,
437
- ] ) ;
445
+ let newJoin = this . joinGraph . buildJoin ( constructJP ( ) ) ;
438
446
while ( newJoin ?. joins . length > 0 && ! R . equals ( this . join , newJoin ) ) {
439
447
this . join = newJoin ;
440
448
joinMembersJoinHints = this . collectJoinHintsFromMembers ( this . joinMembersFromJoin ( ) ) ;
441
- newJoin = this . joinGraph . buildJoin ( [
442
- ...this . queryLevelJoinHints ,
443
- ...allMembersJoinHints ,
444
- ...joinMembersJoinHints ,
445
- ...customSubQueryJoinHints ,
446
- ] ) ;
449
+ newJoin = this . joinGraph . buildJoin ( constructJP ( ) ) ;
447
450
}
448
451
449
- this . collectedJoinHints = [
450
- ...this . queryLevelJoinHints ,
451
- ...allMembersJoinHints ,
452
- ...joinMembersJoinHints ,
453
- ...customSubQueryJoinHints ,
454
- ] ;
452
+ this . collectedJoinHints = constructJP ( ) ;
455
453
456
454
this . join = prevJoins ;
457
455
}
0 commit comments