【发布时间】:2017-11-15 09:03:09
【问题描述】:
我正在尝试使用PagingAndSortingRepository、hibernate 和 SQL Server 2014 在春季实现服务器端分页。它工作正常,但性能似乎有些问题。
页面越远,加载时间越长。
hibernate 记录的查询如下(我已经删除了大部分列名):
WITH query
AS (SELECT inner_query.*,
ROW_NUMBER()
OVER (
ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__
FROM ( select TOP(?) incidentli0_.IncidentId as Incident1_18_
FROM IncidentList incidentli0_ order by incidentli0_.IncidentId desc
) inner_query )
SELECT Incident1_18_
FROM query
WHERE __hibernate_row_nr__ >= ? AND __hibernate_row_nr__ < ?
根据this answer,这是 SQL Server 分页查询的正确方式。
当表中有 400 000 行时,查询最后一页大约需要 1.2 秒,第一页大约需要 60 毫秒。
使用 Eclipse 的 SQL 客户端执行查询需要几毫秒,不知道我要查询什么页面。
我正在使用 4.3.10.Final 版本的 hibernate 和 1.10.2.RELEASE 版本的 spring-data-jpa。
您知道导致此类性能问题的原因以及如何解决吗?
【问题讨论】:
标签: sql-server spring hibernate jpa spring-data