woowacourse-teams / 2023-festa-go

🎪 페스타고, 대학 축제를 더욱 즐겁게!
71 stars 8 forks source link

[BE] FestivalIdStageArtistsQueryDslResolver에서 distinct와 order를 제거하고, 도메인 로직에 해당 조건을 추가한다. #1003

Open seokjin8678 opened 3 months ago

seokjin8678 commented 3 months ago

✨ 세부 내용

FestivalQueryInfo를 업데이트하는 로직에서 FestivalIdStageArtistsQueryDslResolver를 사용하여 해당 축제에 참여하는 아티스트를 조회할 때, 쿼리에 다음과 같이 distinctorder를 사용하여 중복이 없고, 아티스트 식별자 오름차순인 아티스트 목록을 조회합니다.

@Override
public List<Artist> resolve(Long festivalId) {
    return queryDslHelper.select(artist)
        .from(festival)
        .join(stage).on(stage.festival.id.eq(festival.id))
        .join(stageArtist).on(stageArtist.stageId.eq(stage.id))
        .join(artist).on(artist.id.eq(stageArtist.artistId))
        .where(festival.id.eq(festivalId))
        .orderBy(artist.id.asc())
        .distinct()
        .fetch();
}

해당 쿼리의 실행 계획을 보면 cost는 다음과 같습니다.

image

distinctorder 때문에 임시 테이블을 사용해야 하는 것을 볼 수 있습니다.

따라서 해당 조건을 어플리케이션 레벨에서 수행하도록 하여 쿼리 cost를 낮추는 것이 좋을 것 같습니다.

또한 쿼리 cost를 낮추는 것 뿐 아니라, 중복 제거, 정렬 조건을 비즈니스 로직으로 생각할 때, 쿼리에 해당 조건이 포함되는 것이 올바르지 않은 것 같네요.

⏰ 예상 소요 시간

30분