-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/#83 problem 조회 쿼리 개선 및 코드 리팩토링 #95
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
새로운 도메인 cors 설정 추가
swagger 설정 변경
Master docker-compose 변경
좋은 코드 잘봤습니다! 조회 쿼리 관련 고민을 많이 한게 느껴지네요. 문항세트 쪽도 연관관계가 하나만 늘어나고, 동일한 구조인데 많이 참고하겠습니다! |
seokbeom00
approved these changes
Mar 23, 2025
Comment on lines
+22
to
+25
@Query("SELECT DISTINCT p FROM Problem p " + | ||
"LEFT JOIN FETCH p.childProblems c " + | ||
"WHERE p.id = :id") | ||
Optional<Problem> findByIdWithFetchJoin(@Param("id") Long id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그럼 hibernate6부터는 해당 distinct를 제거해도 내부적으로 추가되는 걸까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 맞습니다
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
💡 Issue
📄 Description
해결 방법
위와 같이 개념 태그를 조인해올 때 새끼문항 3개에 대해 3개의 쿼리가 나가는 걸 하나의 in절로 보내는 것을 볼 수 있습니다.
일대다 연관관계가 중첩된다고 항상 fetch join을 2번하지않고 batch size을 하는것은 좋은 방향은 아닌 것 같습니다.
저희 상황에서는 problem에 데이터가 많고 중복이 많이 될 수 있어 메모리 부하를 낮출 필요가 있다고 판단했지만 메인 select할 엔티티의column 개수가 많지 않다면 fetch join 여러번해도 괜찮다는 생각이 듭니다.
💬 To Reviewers
🔗 Reference
[참고1] https://www.inflearn.com/community/questions/34469/default-batch-fetch-size-%EA%B4%80%EB%A0%A8%EC%A7%88%EB%AC%B8
[참고2] https://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch20.html#performance-fetching-batch