작성
·
724
·
수정됨
0
ToOne관계만 우선 모두 페치 조인으로 최적화,
컬렉션 관계는 배치사이즈로 최적화 하는 부분입니다.
@ManyToOne 에서
컬렉션이 아닌 부분들은
join fetch해서 필요한 파트 땡겨온다고 배웠습니다.
그런 후 ,한편
컬렉션인 부분은 default batch size로 전체필드에적용해서
인쿼리로 가져온다고 들었습니다.
예를들어 Order 클래스에 컬렉션
List<OrderItem> orderItems
이 있으면 Orderitems 의 프라이머리 키 만큼
인쿼리를 날리는 쿼리 ,
그리고
OrderItems안에 들어있는 Item의 프라이머리 키 만큼
인쿼리를 날리는 쿼리
============================
강의에서 날린 쿼리 기록을 보면
select
order0_.order_id as order_id1_6_0_,
member1_.member_id as member_i1_4_1_,
delivery2_.delivery_id as delivery1_2_2_,
order0_.delivery_id as delivery4_6_0_,
order0_.member_id as member_i5_6_0_,
order0_.order_date as order_da2_6_0_,
order0_.status as status3_6_0_,
member1_.city as city2_4_1_,
member1_.street as street3_4_1_,
member1_.zipcode as zipcode4_4_1_,
member1_.name as name5_4_1_,
delivery2_.city as city2_2_2_,
delivery2_.street as street3_2_2_,
delivery2_.zipcode as zipcode4_2_2_,
delivery2_.status as status5_2_2_
from
orders order0_
inner join
member member1_
on order0_.member_id=member1_.member_id
inner join
delivery delivery2_
on order0_.delivery_id=delivery2_.delivery_id limit ?
2023-01-30 17:24:30.973 DEBUG 11572 --- [nio-8080-exec-5] org.hibernate.SQL :
select
orderitems0_.order_id as order_id5_5_1_,
orderitems0_.order_item_id as order_it1_5_1_,
orderitems0_.order_item_id as order_it1_5_0_,
orderitems0_.count as count2_5_0_,
orderitems0_.item_id as item_id4_5_0_,
orderitems0_.order_id as order_id5_5_0_,
orderitems0_.order_price as order_pr3_5_0_
from
order_item orderitems0_
where
orderitems0_.order_id in (
?, ?
)
2023-01-30 17:24:30.980 DEBUG 11572 --- [nio-8080-exec-5] org.hibernate.SQL :
select
item0_.item_id as item_id2_3_0_,
item0_.name as name3_3_0_,
item0_.price as price4_3_0_,
item0_.stock_quantity as stock_qu5_3_0_,
item0_.artist as artist6_3_0_,
item0_.etc as etc7_3_0_,
item0_.author as author8_3_0_,
item0_.isbn as isbn9_3_0_,
item0_.actor as actor10_3_0_,
item0_.director as directo11_3_0_,
item0_.dtype as dtype1_3_0_
from
item item0_
where
item0_.item_id in (
?, ?, ?, ?
)
========================
총 3개입니다.
컬렉션이 아닌 부분들에도 Batch Size 영향이 미쳤을텐데..
컬렉션이 아닌 부분들에 배치사이즈 영향이 안미친 이유가 join fetch로 이미 영속성에 존재해서 그런건가요?
Member, Delivery도
Batch Size 영향을 받았으니
여기도 인쿼리 날려줘야 되지 않나 생각이 들었어요
답변 1
1
안녕하세요. pmsuk7028님
fetch join을 사용하게 되면 이미 SQL에서 조회를 해버린 상태가 됩니다.
따라서 batch size에 영향을 받지 않습니다.
감사합니다.