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

推荐订阅源

Y
Y Combinator Blog
GbyAI
GbyAI
U
Unit 42
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
D
DataBreaches.Net
N
Netflix TechBlog - Medium
H
Hackread – Cybersecurity News, Data Breaches, AI and More
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
Martin Fowler
Martin Fowler
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
MyScale Blog
MyScale Blog
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
罗磊的独立博客
B
Blog RSS Feed
J
Java Code Geeks
The GitHub Blog
The GitHub 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