jpa의 existsBy는
count(*) from table where ...
형식의 쿼리가 날라간다.
이 경우 table row 전체와 col 전체를 조회하기 때문에 크면 클수록 성능이 저하된다.
따라서
jpaQueryFactory
.select(table.id)
.from(table)
.where(expression)
.fetchFirst();
select id from table where expression limit ?
와 같은 query dsl 을 사용해서 select로 col의 개수를 제한하고,
fetchFirst로 limit 사용을 유도한다.
결과가 없으면 null, 있으면 id type으로 반환된다.
'Spring' 카테고리의 다른 글
[Java] Optional 사용법 (0) | 2022.02.07 |
---|---|
[spring JPA] Page, PageRequest 메서드 정리 (0) | 2022.02.07 |
[Pageable, PageRequest] Request Param 따로 받아 Pageable 생성해서 주입하기 (0) | 2022.02.04 |
[spring] @RequetParam, @ModelAttribute (0) | 2022.02.02 |
[Jackson]양방향 관계Bidiractional relationship의 무한 참조Infinite recursion문제 (0) | 2021.09.04 |