Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE INDEX idx_nh_status_deadline
ON notification_history (status, deadline);
Comment on lines +1 to +2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인덱스 컬럼 순서 선택 (status 선행, deadline 후행)은 두 쿼리의 사용 패턴에 잘 맞습니다.

다만 두 쿼리에서 이 인덱스가 활용되는 방식이 다릅니다:

findAllRetryableCycles — 인덱스를 완전히 활용

WHERE nh.status = :status      -- status 등치 조건 → 인덱스 선두 컬럼
  AND nh.deadline > :now        -- deadline 범위 조건 → 인덱스 후행 컬럼

(status, deadline) 복합 인덱스가 두 컬럼 모두 활용되어 range 스캔으로 개선됩니다.

findAllByScheduledAtstatus prefix만 활용

WHERE rc.scheduledAt <= :scheduledAt   -- review_cycle 테이블 컬럼 (인덱스 무관)
  AND nh.status = :status              -- status 등치 조건만 해당

이 쿼리에는 deadline이 WHERE 조건에 없으므로 status prefix만 사용됩니다 (EXPLAIN의 ref 결과가 이를 반영). 해당 쿼리 단독이라면 (status) 단일 인덱스와 동일한 효과이지만, findAllRetryableCycles를 위해 deadline을 추가한 설계이므로 두 쿼리를 하나의 인덱스로 커버하는 합리적인 선택입니다.

추가로 findAllByScheduledAtrc.scheduledAt <= :scheduledAt 조건은 review_cycle 테이블을 필터링하는데, review_cycle.scheduled_at에 인덱스가 없다면 이 부분에서도 풀스캔이 발생할 수 있습니다. 데이터 규모가 커질 경우 review_cycle(scheduled_at) 인덱스도 함께 검토해보면 좋을 것 같습니다.

Loading