Skip to content

[refact] #6 - 주문 품목 이력 조회 N+1 문제 해결 및 인덱싱 추가#7

Open
pilltong22 wants to merge 1 commit intodevelopfrom
refact/order-history-n+1
Open

[refact] #6 - 주문 품목 이력 조회 N+1 문제 해결 및 인덱싱 추가#7
pilltong22 wants to merge 1 commit intodevelopfrom
refact/order-history-n+1

Conversation

@pilltong22
Copy link
Contributor

@pilltong22 pilltong22 commented Jan 26, 2026

  • N+1 문제 JOIN 으로 개선
  • INDEX 추가

Pull Request

ISSUE

Develop

주문 품목 이력 조회 API에서 품목 N개당 서브쿼리 7개가 실행되는 N+1 문제를 발견. 서브쿼리를 LEFT JOIN + GROUP BY로 통합하고, 누락된 인덱스를 추가.

Test

테스트 환경

  • Performance Testing Ngrinder
  • API: GET /orders/40/item-history/latest
  • VUser: 99명
  • 테스트 시간: 1분
  • 품목 수: 50개

문제점

  • 품목당 서브쿼리 7개 실행 (7N+1 쿼리)
  • sales_order_item_history.so_item_id에 인덱스 없음
  • 품목 50개 기준 → 351개 쿼리 실행

Before

image
지표
TPS 77.4
Peak TPS 102.5
평균 응답시간 1,352.72ms

After

image
지표
TPS 139.0
Peak TPS 426.0
평균 응답시간 663.93ms

Before vs After 비교

지표 Before After 변화 개선율
TPS 77.4 139.0 +61.6 +79.6%
Peak TPS 102.5 426.0 +323.5 +315.6%
평균 응답시간 1,352.72ms 663.93ms -688.79ms -50.9%
처리량 3,612건 7,234건 +3,622건 +100.3%
쿼리 수 (N=50) 351개 1개 -350개 -99.7%

- N+1 문제 JOIN 으로 개선
- INDEX 추가
@pilltong22 pilltong22 added this to the 1주차 리팩토링 milestone Jan 26, 2026
@pilltong22 pilltong22 self-assigned this Jan 26, 2026
@pilltong22 pilltong22 changed the title [refact] #6 - SOMapper 수정 [refact] #6 - 주문 품목 이력 조회 N+1 문제 해결 및 인덱싱 추가 Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant