Home > Database > Mysql Tutorial > Oracle数据库查询高效分页

Oracle数据库查询高效分页

WBOY
Release: 2016-06-07 15:13:07
Original
1216 people have browsed it

Linq提供了Skip和Take的API可以用于分页,由于使用的是Entity Framework,在好奇的驱使下用EFProfiler查看生成的SQL,才知道这样以下分页更好。 主要就是使用了row_numer()over()这样的分析函数,可以直接找到那第5000行开始的地方,然后在取出30行就行

    Linq提供了Skip和Take的API可以用于分页,由于使用的是Entity Framework,在好奇的驱使下用EFProfiler查看生成的SQL,才知道这样以下分页更好。 主要就是使用了row_numer()over()这样的分析函数,可以直接找到那第5000行开始的地方,然后在取出30行就行了。

<ol>
<li><span><span>select</span><span> * </span></span></li>
<li><span>  <span>from</span><span> (</span><span>select</span><span> * </span></span></li>
<li><span>          <span>from</span><span> (</span><span>select</span><span> t.*, </span></span></li>
<li><span>                       row_number() OVER(<span>ORDER</span><span> </span><span>BY</span><span> </span><span>null</span><span>) </span><span>AS</span><span> </span><span>"row_number"</span><span> </span></span></li>
<li><span>                  <span>from</span><span> yz_bingrenyz t) p </span></span></li>
<li><span>         <span>where</span><span> p.</span><span>"row_number"</span><span> > 5000 </span></span></li>
<li><span>        ) q </span></li>
<li><span> <span>where</span><span> rownum </span></span></li>
</ol>
Copy after login

比较分析:

本机测试前者耗时1.3s,后者仅0.25s,从以下的执行计划也能看出差异来。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template