카드 표시값 파생 조회의 전량 스캔 제거 - #974
Open
m-a-king wants to merge 1 commit into
Open
Conversation
- `where s.id in (select max(s2.id) ...)` 한 문장이 item_snapshots 를 전량 스캔하고 있었다. 부하테스트(#911) 실측: 위시 목록 1회(size=20)가 행 10만을 읽고 483ms 를 썼다 - EXPLAIN ANALYZE 로 계획을 확인했다. 서브쿼리는 19행/76ms 로 정확한데, MySQL 이 그 결과를 임시 테이블로 materialize 한 뒤 바깥 테이블 10만 행을 훑으며 매 행을 대조한다(loops=101184). 안쪽이 좁은데 바깥을 다 보는 형태라 데이터가 늘수록 선형으로 나빠진다 - id 목록을 앱으로 받아 findAllById 로 넘긴다. 1단계는 idx_item_snapshots_item_id range scan(0.24ms), 2단계는 PK lookup 이라 양쪽 모두 인덱스를 탄다. 왕복이 하나 늘지만 1단계 비용이 그것을 크게 밑돈다 - 같은 요청의 다른 `id in (상수)` 쿼리는 examined=20·0.4ms 로 정상이었다. IN 문법이 아니라 서브쿼리를 끼운 형태가 원인이다 - 반환 타입이 엔티티에서 id 목록으로 바뀌어 메서드명도 findLatestMachineReadyIdsByItemIds 로 옮겼다. 조합은 Impl 이 맡아 호출부(ItemDisplayService) 시그니처는 그대로다
|
Discord 스레드 연동용 메타데이터입니다. discord-pr-bot 워크플로가 자동 생성하며, 수정·삭제하면 PR 과 Discord 알림 연동이 끊깁니다. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Situation
Task
Action
원인 규명
EXPLAIN ANALYZE로 실행계획을 확인했다.안쪽이 19행으로 좁은데 바깥 10만 행을 전부 훑으며 대조한다. MySQL 이 서브쿼리 결과를 임시 테이블로 만든 뒤, 바깥 테이블을 스캔하며 매 행을 그 테이블과 맞춰보는 계획을 골랐다. 방향이 반대다.
같은 요청의 다른
id in (상수)쿼리는examined=20, 0.4ms 로 정상이었다. IN 문법이 아니라 서브쿼리를 끼운 형태가 원인이다.수정
한 문장을 두 문장으로 나눠, id 목록을 앱에서 받아 넘긴다.
where s.id in (select max(s2.id) ...)한 문장findAllById두 문장idx_item_snapshots_item_idrange scan왕복이 하나 늘지만 1단계가 0.24ms 라 그 비용을 크게 밑돈다.
반환 타입이 엔티티에서 id 목록으로 바뀌어 메서드명도
findLatestMachineReadyIdsByItemIds로 옮겼다. 조합은Impl이 맡아 호출부(ItemDisplayService) 시그니처는 그대로다.검토 후 채택 안 한 안
Result
in (select max ...))이 코드베이스 다른 곳에 있는지 전수 검사했고, 없었다.연관 이슈