Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 스프링
- Proxy
- SpringBoot
- kotlin
- jpa
- 자바
- db
- 스프링 핵심 원리
- 인프런
- Greedy
- spring
- JDBC
- JPQL
- Servlet
- 알고리즘
- transaction
- AOP
- 그리디
- http
- 김영한
- Exception
- pointcut
- QueryDSL
- Android
- 스프링 핵심 기능
- Spring Boot
- Thymeleaf
- 백준
- springdatajpa
- java
Archives
- Today
- Total
개발자되기 프로젝트
CountQuery 최적화 본문
1. CountQuery 최적화
- PageableExecutionUtils.getPage(content, pageable, () -> ~.fetchCount())
- CountQuery를 날릴려면 fetchCount()가 호출 되어야 함.
- PageableExecutionTuils.getPage()를 통해 count 쿼리가 생략 가능한 경우는 Countquery 생략
- 페이지 시작이면서 컨텐츠 사이즈가 페이지 사이즈보다 작을 때
- 마지막 페이지 일 때 (offset + 컨텐츠 사이즈를 더해서 전체 사이즈 구함)
@Override
public Page<MemberTeamDto> searchPageComplex(MemberSearchCondition condition, Pageable pageable) {
//content를 바로 가져오고.
List<MemberTeamDto> content = queryFactory
.select(new QMemberTeamDto(
member.id.as("memberId"),
member.username,
member.age,
team.id.as("teamId"),
team.name.as("teamName")))
.from(member)
.leftJoin(member.team, team)
.where(
usernameEq(condition.getUsername()),
teamNameEq(condition.getTeamName()),
ageGoe(condition.getAgeGoe()),
ageLoe(condition.getAgeLoe()))
.offset(pageable.getOffset())
.limit(pageable.getPageSize()) //페이지 당 몇 개?
.fetch();
//count쿼리는 직접 날림.
JPAQuery<Member> countQuery = queryFactory
.select(member)
.from(member)
.leftJoin(member.team, team)
.where(
usernameEq(condition.getUsername()),
teamNameEq(condition.getTeamName()),
ageGoe(condition.getAgeGoe()),
ageLoe(condition.getAgeLoe()));
return PageableExecutionUtils.getPage(content, pageable, () -> countQuery.fetchCount() );
// return new PageImpl<>(content, pageable, total);
}
2. GitHub : 210905 CountQuery
'인프런 > [인프런] QueryDsl' 카테고리의 다른 글
인터페이스 지원 : QuerydslPredicateExecutor (0) | 2021.09.05 |
---|---|
Controller, Paging, Sorting (0) | 2021.09.05 |
Querydsl 페이징 연동 (0) | 2021.09.04 |
SpringDataJPA Repository, 사용자 정의 repository (0) | 2021.09.04 |
API 개발 (0) | 2021.09.04 |
Comments