mysql中not in,not exists与join的is null效率对比
来源:互联网 发布:linux c mkdir函数 编辑:程序博客网 时间:2024/06/05 16:16
a表查询出关联字段在b表中不出现的所有记录,现在两数据表有数据大概都约为2万5千条记录,b表相对a表少了230条记录,所以要查询a表多出来的记录,关联字段是a表的id与b表aid,查询方法分别用常见的三种方法
代码如下复制代码select a.id from a left join b ON a.id=b.aid where b.aid is NULL;
select a.id from a where a.id not in (select b.aid from b);
select a.id from a where not exists (select null from b where b.aid=a.id);
用join的is null方法结果:230 rows in set(39 min 0.48 sec)
not in方法结果:230 rows in set (38 min 7.48 sec)
not exists方法结果:230 rows in set (37 min 52.44 sec)
晕了,为什么都是这样慢呢?哪里出错了?
原来b表的aid没建索引,建立索引后再查询就快了很多很多,索引后再查询三种方法大概都只用了0.52sec就出来结果了,索引与没索引会有这样强烈的差异,所以对于这种查询,一定要对关联字段建立索引哦,要不你就只有接受龟迅了!
0 0
- mysql中not in,not exists与join的is null效率对比
- NOT IN、JOIN、IS NULL、NOT EXISTS效率对比
- NOT IN、JOIN、IS NULL、NOT EXISTS效率对比
- NOT IN NOT EXISTS LEFT JOIN/ IS NULL
- IN、EXISTS和LEFT JOIN,NOT IN、NOT EXISTS和INNER JOIN在存在与不存在的查询效率
- IN、EXISTS和LEFT JOIN,NOT IN、NOT EXISTS和INNER JOIN在存在与不存在的查询效率
- IN、EXISTS和LEFT JOIN,NOT IN、NOT EXISTS和INNER JOIN在存在与不存在的查询效率
- oracle中in和exists、not in和not exists的用法与效率
- mysql中in与exists的性能与效率对比
- mysql中null与not null的区别及效率
- mysql not exists 和 not in对比
- MySql中IS NOT NULL与!=NULL的区别
- sql中 in , not in , exists , not exists效率分析
- not in/not exists 的 null 陷阱
- not in/not exists 的 null 陷阱
- not in/not exists 的 null 陷阱
- not in/not exists 的 null 陷阱
- not in,not exists,left join性能对比
- Oracle资源管理器在HIS系统中的应用
- mysql----快速删除数据表(drop,truncate.delete)
- 使用简单的shell脚本进行自动化测试
- Server-sent Events和 websocket
- C#数据列表控件取消每列前面的框
- mysql中not in,not exists与join的is null效率对比
- 如何安装.NET 4
- 解决ENT-06969:Dimension Name does not exists in olap schema
- C#调用c++的dll 回调使用方法
- 学完了《数据结构》、《软件工程》、《C语言》
- loadrunner analysis 设置axis 使曲线变得平滑
- 关于数组计数的巧妙使用
- 本来挺好的事,怎么弄成现在这种样子
- Windows SetTimer的使用