Skip to content

Commit dfea6d1

Browse files
mbelladebeikov
authored andcommitted
HHH-17629 Reuse compatible joins for entity graphs and fetch profiles
1 parent 7bf5604 commit dfea6d1

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7972,21 +7972,33 @@ else if ( getLoadQueryInfluencers().hasEnabledFetchProfiles() ) {
79727972
fetchablePath,
79737973
np -> {
79747974
// generate the join
7975+
final TableGroup tableGroup;
79757976
final TableGroup lhs = fromClauseIndex.getTableGroup( fetchParent.getNavigablePath() );
7976-
final TableGroupJoin tableGroupJoin = ( (TableGroupJoinProducer) fetchable ).createTableGroupJoin(
7977-
fetchablePath,
7978-
lhs,
7979-
alias,
7980-
null,
7981-
null,
7982-
true,
7983-
false,
7984-
BaseSqmToSqlAstConverter.this
7977+
final TableGroupJoinProducer joinProducer = (TableGroupJoinProducer) fetchable;
7978+
final TableGroup compatibleTableGroup = lhs.findCompatibleJoinedGroup(
7979+
joinProducer,
7980+
joinProducer.determineSqlJoinType( lhs, null, true )
79857981
);
7986-
lhs.addTableGroupJoin( tableGroupJoin );
7982+
if ( compatibleTableGroup == null ) {
7983+
final TableGroupJoin tableGroupJoin = joinProducer.createTableGroupJoin(
7984+
fetchablePath,
7985+
lhs,
7986+
alias,
7987+
null,
7988+
null,
7989+
true,
7990+
false,
7991+
BaseSqmToSqlAstConverter.this
7992+
);
7993+
lhs.addTableGroupJoin( tableGroupJoin );
7994+
tableGroup = tableGroupJoin.getJoinedGroup();
7995+
}
7996+
else {
7997+
tableGroup = compatibleTableGroup;
7998+
}
79877999

79888000
// and return the joined group
7989-
return tableGroupJoin.getJoinedGroup();
8001+
return tableGroup;
79908002
}
79918003
);
79928004
}

0 commit comments

Comments
 (0)