问题描述
因此,代码非常简单:
var result = dbContext.Skip(x).Take(y).ToList();
当x大(〜1.000.000)时,查询非常慢。 y小-10、20。
When x is big (~1.000.000), query is very slow. y is small - 10, 20.
此操作的SQL代码是:(来自sql profiler)
SQL code for this is: (from sql profiler)
SELECT ...
FROM ...
ORDER BY ...
OFFSET x ROWS FETCH NEXT y ROWS ONLY
问题是,是否有人知道如何加快这种分页?
The question is if anybody knows how to speed up such paging?
推荐答案
我认为 OFFSET
.. FETCH
在从大数据浏览第一页时非常有用(在大多数应用程序中经常发生)
I think OFFSET
.. FETCH
is very useful when browsing the first pages from your large data (which is happening very often in most applications) and have a performance drawback when querying high order pages from large data.
选中此有关性能和 OFFSET ..
FETCH
。
Check this article for more details regarding performance and alternatives to OFFSET
.. FETCH
.
在应用分页之前,尝试对数据应用尽可能多的过滤器,以便分页针对较小的数据量运行。很难想象用户不想浏览100万行。
Try to apply as many filters to your data before applying paging, so that paging is run against a smaller data volume. It is hard to imagine that the user wants no navigate through 1M rows.
这篇关于当要跳过的数字很大时,实体框架的“跳过/获取”非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!