Oracle数据库 Left Join 使用之我见
来源:互联网 发布:c盘windows文件夹30g 编辑:程序博客网 时间:2024/06/05 19:23
在Oracle 9i数据库中使用LEFT JOIN这种连表查询方式的效率是极为低下的。
在项目中使用了这么一条语句:
select tmp2.company_name,sum(tmp2.radio_send_bytes + tmp2.radio_recv_bytes)/(1024*1024*1024) as flow
from
(select *
from
(select * from ap_pm_up a
where a.begin_time >= to_date('2010-06-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
and a.begin_time <= to_date('2010-06-30 23:23:59','yyyy-mm-dd hh24:mi:ss')
) tmp
left join ap_info ap on ap.ap_id=tmp.ap_id
left join company c on c.company_id= ap.company_id
left join hot h on h.hp_id=ap.hp_id
left join hot_type ht on ht.hot_type_id=h.hot_type_id
where ht.hot_type_name='南宁') tmp2
group by tmp2.company_name
此语句在plSql中执行10分钟都没有结果,其中ap_pm_up 表里数据2000多万条。
而把语句中的所有LEFT JOIN去掉,换成子查询的话,语句如下:
select tmp.company_name,
(sum(tmp.radio_recv_bytes + tmp.radio_send_bytes)/(1024*1024*1024)) as flow
from
(
select (select c.company_name
from company c
where c.company_id in
(select ai.company_id from ap_info ai where ai.ap_id = a.ap_id)) as company_name,
a.radio_recv_bytes,
a.radio_send_bytes
from ap_pm_up a
where a.begin_time >=
to_date('2010-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
and a.begin_time <=
to_date('2010-06-30 23:23:59', 'yyyy-mm-dd hh24:mi:ss')
and a.ap_id in
(select ap.ap_id
from ap_info ap
where ap.hp_id in
(select h.hp_id
from hot h
where h.hot_type_id in
(select ht.hot_type_id
from hot_type ht
where ht.hot_type_name = '学校')))
) tmp
group by tmp.company_name
这条语句执行仅用了17.4秒就得出了结果。
第一条语句在SQL Server中使用是没有问题的,但在Oracle 9i中使用,效率就很低了,所以我们在Oracle中尽量避免使用Left Join等关键字,虽然这样看起来比较直观。
- Oracle数据库 Left Join 使用之我见
- mysql数据库之left join与join
- Oracle之left join,right join,inner join,full join
- oracle left join
- oracle left join优化
- 数据库left join
- ORACLE- join,inner join 与 left join, left outer join
- oracle中 left join,right join, inner join,full join的简单使用
- Oracle 数据库left join 的实例@小白
- 数据库:left join,right join,inner join
- 数据库Left join, Right join,Inner join
- left join使用精华:)
- left join使用精华
- oracle join、inner join、left join、right join、full join
- SQL Server数据库之left join 、right join 和 inner join 的区别
- [数据库]sql之left join、right join、inner join的区别
- 数据库存储过程使用左外连接left join
- oracle小记3-left join
- Android画图学习总结(一)——类的简介
- 消失了半个月,我的处女作诞生啦!!!!!
- 一道题:给一个字符串,和一个字符集,求该字符串包含所有字符集的最短子串
- Android画图学习总结(三)——Drawable
- MFC学习之路(四)不够细心,一个小问题蛋疼了一天
- Oracle数据库 Left Join 使用之我见
- Android画图学习总结(四)——Animation(上)
- Http和Socket连接区别
- nginx源码那些事之内存管理模块一
- 外部排序
- oracle 时间差计算
- Android画图学习总结(四)——Animation(下)
- Oracle Sql语句长度限制问题及解决
- Android画图学习总结(四)——Animation(中)