select *
from (
select this.a, this.b, this.state, this.id
from view_user this
where this.state=:1 order by this.a asc, this.b
)
where rownum <= :2
问题:
上述查询执行 - 从SQLDeveloper快速 - 通过使用hibernate的小型Java应用程序快速 - 从使用hibernate的应用程序极慢(>100倍) - 绑定变量的值分别为2和30(rownum来源于分页) - hibernate查询“形式”如上所示。 实际上,视图中有大约20个列。
当前分析状态
- 查询计划显示当查询来自SQlDeveloper或“小型Java应用程序”时使用索引。
- 查询计划显示如果查询来自hibernate应用程序,则执行完整表扫描。
- DB跟踪显示仅存在两个差异:NLS设置(来自SQLDeveloper)和稍微不同的格式(空格)。 其他所有内容似乎都是相同的...
=> 我很高兴有人能够提供有关此问题的任何提示。 令我困扰的是DB跟踪没有显示任何差异... 是的,看起来它与hibernate有关。 但是什么? 如何检测?
Select * from (
select this.USER_ID as USER_ID0_, this.CLIENT_ID as CLIENT_ID0_,
this.USER_NAME as USER_NAME0_, this.USER_FIRST_NAME as USER_FIR5_0_, this.USER_REMARKS as
USER_REM6_0_, this.USER_LOGIN_ID as USER_LOG7_0_, this.USER_TITLE as USER_TITLE0_,
this.user_language_code as user_lan9_0_, this.USER_SEX as USER_SEX0_,
this.USER_BIRTH_DATE as USER_BI11_0_, this.USER_TELEPHONE as USER_TE12_0_,
this.USER_TELEFAX as USER_TE13_0_, this.USER_MOBILE as USER_MO14_0_,
this.USER_EMAIL as USER_EMAIL0_, this.USER_ADDRESSLINE1 as USER_AD16_0_,
this.USER_ADDRESSLINE2 as USER_AD17_0_, this.USER_POSTALCODE as USER_PO18_0_,
this.USER_CITY as USER_CITY0_, this.USER_COUNTRY_CD as USER_CO20_0_,
this.USER_COUNTRY_NAME as USER_CO21_0_, this.USER_STATE_ID as USER_ST24_0_,
this.USER_STATE as USER_STATE0_, this.USER_TEMP_COLL_ID as USER_TE26_0_,
this.USER_TEMP_COLL_NAME as USER_TE27_0_, this.UNIT_ID as UNIT_ID0_,
this.CLIENT_NAME as CLIENT_38_0_, this.PROFILE_EXTID as PROFILE39_0_
from VIEW_USER this
where this.USER_STATE_ID=:1 order by this.USER_NAME asc, this.USER_FIRST_NAME asc
)
where rownum <= :2
唯一索引是基于用户姓名、用户名字和用户ID的。
where
。where rownum
子句实际上是在外部选择中吗? - rejj