hibernate中使用fetch来决策性能方案

什么时候用子查询,或者连接查询

一般多个数据的对应用子查询,单一行的数据用连接

(若要查询每个学生分别学了什么课程 ,若要fetch=join、fetch=select)

则是这种情况

Hibernate:
select
student0_.sid as sid2_,
student0_.s_name as s2_2_
from
student student0_
Hibernate:
select
courses0_.sid as sid2_1_,
courses0_.cid as cid1_,
course1_.cid as cid0_0_,
course1_.c_name as c2_0_0_
from
student_course courses0_
inner join
course course1_
on courses0_.cid=course1_.cid
where
courses0_.sid=?
freedom:odijfoij
freedom:in2
Hibernate:
select
courses0_.sid as sid2_1_,
courses0_.cid as cid1_,
course1_.cid as cid0_0_,
course1_.c_name as c2_0_0_
from
student_course courses0_
inner join
course course1_
on courses0_.cid=course1_.cid
where
courses0_.sid=?
wer:odijfoij
Hibernate:
select
courses0_.sid as sid2_1_,
courses0_.cid as cid1_,
course1_.cid as cid0_0_,
course1_.c_name as c2_0_0_
from
student_course courses0_
inner join
course course1_
on courses0_.cid=course1_.cid
where
courses0_.sid=?
ert:odijfoij
Hibernate:
select
courses0_.sid as sid2_1_,
courses0_.cid as cid1_,
course1_.cid as cid0_0_,
course1_.c_name as c2_0_0_
from
student_course courses0_
inner join
course course1_
on courses0_.cid=course1_.cid
where
courses0_.sid=?
qqs:odijfoij

子查询的效率:

Hibernate:
select
student0_.sid as sid2_,
student0_.s_name as s2_2_
from
student student0_
Hibernate:
select
courses0_.sid as sid2_1_,
courses0_.cid as cid1_,
course1_.cid as cid0_0_,
course1_.c_name as c2_0_0_
from
student_course courses0_
inner join
course course1_
on courses0_.cid=course1_.cid
where
courses0_.sid in (
select
student0_.sid
from
student student0_
)
freedom:in2
freedom:odijfoij
wer:odijfoij
ert:odijfoij
qqs:odijfoij
上一篇:android 7.0带来的


下一篇:Eclipse中Program arguments和VM arguments的说明