2012-09-26 47 views
0

我有一个HQL查询,像这样:休眠 - HQL帮助优化查询

Select 
... (around 40 items)... 
from 
ATable a 
left outer join a.subA SubA 
left outer join a.subB SubB 
left outer join a.Names Names 
left outer join Names.Addresses Addresses 
left outer join Names.Phones Phones 
left outer join a.Roles Roles 
where 
a.aType.someType in ('...') 
and (Names.id.FKey in('...') or Names.id.FKey is null) 
and upper(a.pin) like upper('some%') 
and upper(Names.lastName) like upper('Some%') 
order by a.pin asc 

出于某种原因出这个时间,但由Hibernate生成的查询(从日志中获得)需要5秒,而使用蟾蜍执行。我是休眠的新手。我很感谢任何帮助优化此感谢。

+0

http://hungred.com/useful-information/ways-optimize-sql-queries/ – shevchyk

回答

0

有两件事我可以建议是:

1]避免使用'IN'子句。 2]如果没有必要,请避免使用订单。

阿米特:)