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

推荐订阅源

J
Java Code Geeks
G
Google Developers Blog
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
博客园 - 聂微东
V
Visual Studio Blog
博客园_首页
D
DataBreaches.Net
腾讯CDC
I
InfoQ
F
Fortinet All Blogs
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
月光博客
月光博客
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog

博客园 - 焰凌

Poor code: Dynamic changing of table schema When we need to inherit from WSS WebPart class? The issue of upload big file on SharePoint with IIS7 Why no effects when change the "Site Master Page Settings" from "Site Actions - Site Settings - Look and Feel - Master Page"? 怎样在MOSS2007和WSS3.0中修改服务帐户和密码 HttpApplication机制 为SharePoint新项目做准备 MOSS 2007 SSP (1) How to create and delete a SharePoint site by web application Search user of specific domain name Received DGT's document 水晶报表PUSH模式多个表数据的显示 上海电信之具有地域歧视的霸王条款 来上海一年多了,第一次感冒! differentia of [string str=null;] and [string str="";] 搬家了,没宽带了 工作以后 找不到状态了! 页面缓存的困扰
"NOT IN", "JOIN...IS NULL", "NOT EXISTS" 之间的效率对比
焰凌 · 2007-11-20 · via 博客园 - 焰凌

语句一:select count(*) from A where A.a not in (select a from B)

语句二:select count(*) from A left join B on A.a = B.a where B.a is null

语句三:select count(*) from A where not exists (select a from B where A.a = B.a)

知道以上三条语句的实际效果是相同的已经很久了,但是一直没有深究其间的效率对比。一直感觉上语句二是最快的。
今天工作上因为要对一个数千万行数据的库进行数据清除,需要删掉两千多万行数据。大量的用到了以上三条语句所要实现的功能。本来用的是语句一,但是结果是执行速度1个小时32分,日志文件占用21GB。时间上虽然可以接受,但是对硬盘空间的占用确是个问题。因此将所有的语句一都换成语句二。本以为会更快。没想到执行40多分钟后,第一批50000行都没有删掉,反而让SQL SERVER崩溃掉了,结果令人诧异。试了试单独执行这条语句,查询近一千万行的表,语句一用了4秒,语句二却用了18秒,差距很大。语句三的效率与语句一接近。

如果有哪位有经验的朋友对大数据量删除操作有经验。请不吝告知如何避免日志文件过大的问题。谢谢