NHibernate排序性能

发布于 2024-12-05 06:00:42 字数 847 浏览 7 评论 0原文

我在排序的查询上遇到一些负面性能。

这就是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命比纸薄 2024-12-12 06:00:42

通过数据库优化顾问运行查询,很可能存在丢失(或损坏)的索引。

Run the query through the database tuning advisor, most likely there is a missing (or bad) index.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文