Uh oh!
There was an error while loading. Please reload this page.
perf: FK 컬럼에 누락된 인덱스 5건 추가 - #244
Merged
Merged
Conversation
PostgreSQL은 MySQL(InnoDB)과 달리 FK 컬럼을 자동으로 인덱싱하지 않는다. course/record/user_stamp/scrap/heart_rate_sample의 FK 컬럼에 인덱스가 없어 관련 조회가 Seq Scan으로 처리되고 있었다. EXPLAIN (ANALYZE, BUFFERS)로 30만 건 규모 합성 데이터에서 실측: - course.user_id: 52.516ms → 3.258ms (Seq Scan → Bitmap Heap Scan) - record.user_id: 11.081ms → 2.704ms (Parallel Seq Scan → Bitmap Heap Scan) - user_stamp.user_id: 15.984ms → 1.835ms (Seq Scan → Index Scan) - scrap.public_course_id: 3.696ms → 1.233ms (Seq Scan → Bitmap Heap Scan) - heart_rate_sample.record_health_data_id: 8.507ms → 0.429ms (Parallel Seq Scan → Bitmap Heap Scan)
unam98
requested review from
RinRinPARK, YuSuhwa-ve and funnysunny08
as code ownersAugust 12, 2026 08:25
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughChangesDatabase indexes
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Uh oh!
There was an error while loading. Please reload this page.
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 freeto 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.
작업 배경
pg_indexes로 조회해보니course.user_id,record.user_id,user_stamp.user_id,scrap.public_course_id,heart_rate_sample.record_health_data_id5개 FK 컬럼에 인덱스가 없었음Course.path(geometry) 컬럼에 GiST 공간 인덱스가 필요하다고 가정했으나, 코드 전체를 grep한 결과 공간 쿼리(ST_* 함수)를 실제로 사용하는 곳이 없어 기각 — FK 컬럼 누락이 진짜 후보였음변경 사항
Course.java@Table(indexes = {@Index(columnList = "user_id")})추가Record.java@Table(indexes = {@Index(columnList = "user_id")})추가UserStamp.java@Table(indexes = {@Index(columnList = "user_id")})추가Scrap.javauniqueConstraints에indexes = {@Index(columnList = "public_course_id")}추가HeartRateSample.java@Table(indexes = {@Index(columnList = "record_health_data_id")})추가ddl-auto: update로 스키마를 관리하므로 별도 마이그레이션 없이 배포 시 자동 반영됨.선택지 및 근거
Course.path(geometry)에 GiST 공간 인덱스 추가 — grep으로 공간 쿼리 미사용 확인 후 기각. 불필요한 인덱스는 쓰기 성능만 깎아먹음영향 범위
검증 매트릭스
30만 건 규모 synthetic 데이터로
EXPLAIN (ANALYZE, BUFFERS)직접 측정 (Docker 로컬 Postgres, 인덱스 추가 전/후 비교):course.user_ididx_course_user_id)record.user_ididx_record_user_id)user_stamp.user_ididx_user_stamp_user_id)scrap.public_course_ididx_scrap_public_course_id)heart_rate_sample.record_health_data_ididx_heart_rate_sample_record_health_data_id)측정 후 synthetic 데이터는 전량 삭제, 실 데이터 baseline 행 수 복원 확인 완료.
Test Plan
./gradlew test, 실 Postgres/Redis 컨테이너 기준)EXPLAIN (ANALYZE, BUFFERS)로 인덱스 전/후 실측 비교🤖 Generated with Claude Code
Summary by CodeRabbit