# perf(remittance): user 최신순 조회 인덱스 추가 + 측정 시드/문서화 - #13
Merged
Conversation
### Summary
`remittances` 사용자별 최신순 조회 쿼리(`WHERE user_id = ? ORDER BY created_at DESC`)의 filesort 비용을 줄이기 위해 `(user_id, created_at)` 복합 인덱스를 추가했습니다.
또한 재현 가능한 성능 측정을 위해 대량 시드 SQL을 추가하고, README에 BEFORE/AFTER 실행 계획과 튜닝 근거를 문서화했습니다.
---
### Changes
#### 1) 인덱스 마이그레이션 추가
- `remittance-api/src/main/resources/db/migration/V6__index_tuning.sql` (신규)
- `ALTER TABLE remittances ADD INDEX idx_remittances_user_created (user_id, created_at);`
- 기존 `idx_remittances_user_status (user_id, status)`는 유지
#### 2) 성능 측정용 시드 스크립트 추가
- `docs/perf/seed.sql` (신규)
- 측정용 대량 데이터 적재 스크립트 추가
- 규모:
- users 10,000
- wallets 10,000
- remittances 500,000
- 측정 후 정리 SQL 포함
#### 3) README 튜닝 사례 문서화
- `README.md`
- `remittances` 사용자 최신순 조회 인덱스 튜닝 섹션 추가
- BEFORE/AFTER `EXPLAIN`, `EXPLAIN ANALYZE` 결과 및 해석 추가
- `(user_id, status)`와 `(user_id, created_at)`를 분리 유지하는 이유 명시
---
### Checklist
- [x] `remittances` 최신순 조회용 인덱스 추가
- [x] 성능 측정 재현용 시드 SQL 추가
- [x] 튜닝 근거 및 실행 계획 문서화
---
### How to Test
```bash
# 1) 마이그레이션 적용
./gradlew :remittance-api:bootRun
# 2) 측정용 시드 적재
docker exec -i openremit-mysql mysql -uroot -prootpw openremit < docs/perf/seed.sql
# 3) 실행 계획 확인
docker exec -it openremit-mysql mysql -uroot -prootpw openremit -e "
EXPLAIN ANALYZE
SELECT * FROM remittances
WHERE user_id = <USER_ID>
ORDER BY created_at DESC;
"
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.
Summary
remittances사용자별 최신순 조회 쿼리(WHERE user_id = ? ORDER BY created_at DESC)의 filesort 비용을 줄이기 위해(user_id, created_at)복합 인덱스를 추가했습니다. 또한 재현 가능한 성능 측정을 위해 대량 시드 SQL을 추가하고, README에 BEFORE/AFTER 실행 계획과 튜닝 근거를 문서화했습니다.Changes
1) 인덱스 마이그레이션 추가
remittance-api/src/main/resources/db/migration/V6__index_tuning.sql(신규)ALTER TABLE remittances ADD INDEX idx_remittances_user_created (user_id, created_at);idx_remittances_user_status (user_id, status)는 유지2) 성능 측정용 시드 스크립트 추가
docs/perf/seed.sql(신규)3) README 튜닝 사례 문서화
README.mdremittances사용자 최신순 조회 인덱스 튜닝 섹션 추가EXPLAIN,EXPLAIN ANALYZE결과 및 해석 추가(user_id, status)와(user_id, created_at)를 분리 유지하는 이유 명시Checklist
remittances최신순 조회용 인덱스 추가How to Test