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

推荐订阅源

GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
J
Java Code Geeks
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI

博客园 - 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