fix: 랭킹 조회 시 sort_buffer 초과로 발생하는 Out of sort memory 예외 수정#35
Draft
Jeongho0805 wants to merge 1 commit into
Draft
fix: 랭킹 조회 시 sort_buffer 초과로 발생하는 Out of sort memory 예외 수정#35Jeongho0805 wants to merge 1 commit into
Jeongho0805 wants to merge 1 commit into
Conversation
ROW_NUMBER() 윈도우 함수를 CTE + GROUP BY 방식으로 교체해 MySQL sort_buffer_size 의존 제거
This file contains hidden or 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
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.
변경 사항
PracticeRankRepositoryImpl.findRanking의ROW_NUMBER() OVER (PARTITION BY client_key ORDER BY total_duration_ms ASC, id ASC)윈도우 함수를 CTE + GROUP BY 방식으로 교체배경
Sentry 이슈 PRACTICKET-5G:
GET /api/practice/rank요청에서JpaSystemException → GenericJDBCException → SQLException: Out of sort memory, consider increasing server sort buffer size예외 발생.ROW_NUMBER() OVER (PARTITION BY client_key ORDER BY ...)윈도우 함수는WHERE type = ? AND started_at >= ?조건을 만족하는 전체 행을 MySQL이 메모리에서 정렬해야 한다. practice_result 테이블이 커질수록 정렬 대상 데이터가 서버의sort_buffer_size를 초과해 예외로 이어진다.CTE + GROUP BY로 교체하면 MySQL 옵티마이저가 sort-based 집계 대신 hash-based 집계를 선택할 수 있어 sort_buffer 의존 없이 클라이언트별 최적 행을 도출한다. 근본적인 해결을 위해서는
(type, started_at, client_key, total_duration_ms, id)복합 인덱스 생성도 병행 검토 필요.