惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
L
LangChain Blog
M
MIT News - Artificial intelligence
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
P
Proofpoint News Feed
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
博客园_首页
Blog — PlanetScale
Blog — PlanetScale
U
Unit 42
I
InfoQ
月光博客
月光博客
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
Y
Y Combinator Blog
Microsoft Security Blog
Microsoft Security Blog
博客园 - Franky
D
Docker
B
Blog

博客园 - nasdaqhe

Frida 使用 Android https 抓包 云效流水线部署ack Android 解包重签名打包 centos7 docker 安装及配置 CentOS 6 升级 curl Mac 下编译安装 php-5.6 ubuntu+php5-fpm 下安装 memcached PHP扩展 cmd下使用telnet连接到memcached服务器操作 Lucence.Net 2.9.3 日期范围搜索 flickr head中用到的标签 - nasdaqhe - 博客园 判断中文是否UTF8编码 MSSQL备忘 新浪微博产品图 (Vincent.H手笔) MindManage HTML5学习资料整理 ubuntu备忘 const 与 readonly ubuntu 10.04 安装 oracle11g VS2010 .NET 4学习资料整理
SQL语句优化一例 row_number not in or
nasdaqhe · 2011-04-07 · via 博客园 - nasdaqhe

Posted on 2011-04-07 09:29  nasdaqhe  阅读(303)  评论()    收藏  举报

select [id],[poster],[fid],[title],[editername],[modifytime] from(

select [id],[poster],[fid],[title],[editername],[modifytime], row_number() over

( order by id desc) as row from [news] WITH (NOLOCK) 

 where   path like 'A_B%' and  id not in 

 (select id from [news] where layer=7 or layer=5)) a  

 where row between 1 and 15

 上面的查询很慢。如果只执行子查询就很快,但是做 where row between 1 and 15 分页就很慢很慢,原来是因为查询里面用了or,优化成下面的就不超时了

 select [id],[poster],[fid],[title],[editername],[modifytime] from(

select [id],[poster],[fid],[title],[editername],[modifytime], row_number() over

( order by id desc) as row from [news] WITH (NOLOCK) 

 where   path like 'A_B%' and  id not in 

 (select id from [news] where layer=7 union select id from [news] where layer=5)) a  

 where row between 1 and 15