You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
여행
전체 여행을 조회하면 아래와 같은 순서로 쿼리가 실행됩니다.
이때 3번 회원 조회 쿼리가 여행 게시글 작성자의 수만큼 실행됩니다. 즉 n+1 문제가 발생합니다.
이는 여행 entity가 회원 entity를 직접 참조하면서, FetchType이 Lazy 로 설정되어 있기 때문입니다.
이러한 문제를 해결하기 위해 2번 여행 조회 쿼리를 아래와 같이 수정했습니다.
여행을 조회할 때 회원도 함께 조회하면 n+1 문제를 해결할 수 있습니다.
코드 상에서는 Trip.Member 에 대해 FETCH JOIN을 추가하면 됩니다.
감상
감상에서도 여행과 상황이 동일합니다. Post.Member 에 대해 FETCH JOIN을 추가해서 해결했습니다.
Beta Was this translation helpful? Give feedback.
All reactions