NHibernate排序性能
我在排序的查询上遇到一些负面性能。
这就是 NHibernate 生成和呈现查询的方式:
SELECT TOP 50 y0_,
y1_
FROM **(SELECT distinct r1_.Id as y0_,
this_.Id as y1_,
ROW_NUMBER()
OVER(ORDER BY this_.Id DESC) as __hibernate_sort_row
FROM Event this_
inner join Registration r1_
on this_.Id = r1_.EventId
WHERE this_.IsDeleted = 0 /* @p2 */
and this_.SportId in (22 /* @p3 */)) as query**
WHERE query.__hibernate_sort_row > 20
ORDER BY query.__hibernate_sort_row;
粗体部分(**符号内)正在获取所有结果并将它们按顺序排列 - 这需要时间。 有什么办法可以让这个查询更有效率吗?我只是想让排序和分页成为可能,而不必产生太多开销。
我正在使用 NHibernate 2.1。未来版本中是否有与我的问题相关的改进?
此致, 马蒂亚斯
I am experiencing some negative performance on queries that are sorted.
This is how the query is being generated and rendered by NHibernate:
SELECT TOP 50 y0_,
y1_
FROM **(SELECT distinct r1_.Id as y0_,
this_.Id as y1_,
ROW_NUMBER()
OVER(ORDER BY this_.Id DESC) as __hibernate_sort_row
FROM Event this_
inner join Registration r1_
on this_.Id = r1_.EventId
WHERE this_.IsDeleted = 0 /* @p2 */
and this_.SportId in (22 /* @p3 */)) as query**
WHERE query.__hibernate_sort_row > 20
ORDER BY query.__hibernate_sort_row;
The bold part(within the **-symbols) is fetching all the results and puts them in order - this is what takes time.
Is there any way i can make this query more efficient? I just want to make sorting and paging possible without having to create too much overhead.
I am using NHibernate 2.1. Any improvements in future releases that relates to my problem?
Best regards,
Mattias
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过数据库优化顾问运行查询,很可能存在丢失(或损坏)的索引。
Run the query through the database tuning advisor, most likely there is a missing (or bad) index.