forked from digma-ai/otel-sample-app-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Issue Description
The Vets endpoint (/vets.html
) is experiencing an N+1 query performance issue due to eager loading of specialties for each vet.
Root Cause
- The
Vet
entity usesFetchType.EAGER
for specialties, causing unnecessary queries - Missing proper join fetching strategy in the repository layer
- No composite index on the
vet_specialties
table for optimized joins
Solution
A pull request (#81) has been created with the following changes:
- Changed
FetchType.EAGER
toFetchType.LAZY
in the Vet entity - Added
@NamedEntityGraph
for efficient fetching of Vet specialties - Updated VetRepository to use
@EntityGraph
annotation - Added composite index on
vet_specialties(vet_id, specialty_id)
Impact
These changes will:
- Prevent unnecessary queries when specialties are not needed
- Optimize fetching when specialties are needed using join fetch
- Improve query performance with proper indexing
Testing
- The changes maintain existing functionality while improving performance
- The EntityGraph ensures efficient loading of specialties when needed
- The composite index will improve join performance
Related
- Original Issue: #e8efc2b4-5f5e-11f0-bbd9-0242ac160009
- Pull Request: Fix N+1 Query Issue in Vets Endpoint-created-by-agentic #81