Skip to content

Commit

Permalink
HHH-17679 Fix unnecessary table reference resolution for treat
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel authored and beikov committed Jan 26, 2024
1 parent 9faa764 commit b15ca55
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,10 @@ public void pruneForSubclasses(TableGroup tableGroup, Map<String, EntityNameUse>
applied = applyDiscriminatorPredicate( join, join.getJoinedTableReference(), entityNameUses, metamodel );
}
assert applied : "Could not apply treat discriminator predicate to root table join";
assert i == 0 || retainedTableReferences.contains( tableReferenceJoins.get( i - 1 ).getJoinedTableReference() );
if ( i != 0 ) {
// Always retain the root table reference join where the discriminator was applied
retainedTableReferences.add( tableReferenceJoins.get( i - 1 ).getJoinedTableReference() );
}
}
}
if ( tableReferenceJoins.isEmpty() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3105,7 +3105,6 @@ private void registerEntityNameUsage(
actualTableGroup.resolveTableReference( null, persister.getTableName() );
}

final EntityNameUse.UseKind useKind = finalEntityNameUse.getKind();
if ( projection ) {
EntityMappingType superMappingType = persister;
while ( ( superMappingType = superMappingType.getSuperMappingType() ) != null ) {
Expand All @@ -3116,19 +3115,17 @@ private void registerEntityNameUsage(
);
}
}

// If we encounter a treat or projection use, we also want register the use for all subtypes.
// We do this here to not have to expand entity name uses during pruning later on
final EntityNameUse.UseKind useKind = finalEntityNameUse.getKind();
if ( useKind == EntityNameUse.UseKind.TREAT ) {
for ( EntityMappingType subType : persister.getSubMappingTypes() ) {
entityNameUses.compute(
subType.getEntityName(),
(s, existingUse) -> finalEntityNameUse.stronger( existingUse )
);
}
if ( persister.isInherited() && persister.needsDiscriminator() ) {
// Make sure the table group includes the root table when needed for TREAT
actualTableGroup.resolveTableReference( persister.getRootTableName() );
}
}
else if ( useKind == EntityNameUse.UseKind.PROJECTION ) {
for ( EntityMappingType subType : persister.getSubMappingTypes() ) {
Expand Down Expand Up @@ -3374,7 +3371,7 @@ private TableGroup consumeAttributeJoin(
// This is a non-treated join with an entity which is an inheritance subtype,
// register a TREAT entity name use to filter only the entities of the correct type.
registerEntityNameUsage(
getActualTableGroup( joinedTableGroup, sqmJoin ),
elementTableGroup,
EntityNameUse.TREAT,
entityDomainType.getHibernateEntityName()
);
Expand Down

0 comments on commit b15ca55

Please sign in to comment.