我这里俩个table,一个hist,一个tbl。
hist中有海量数据,如果查询一周的记录要5分钟,一个月的就要半小时,hist中有个index:histdate
tbl数据较少没有index现在我有俩个查询语句,都是查询一天的数据
select histdate,num,aa from hist
where histdate >= ...
and histdate <=...
用时约0.1mselect histdate,num,bb from tbl
where histdate>=..
and histdate <= ..
用时约0.03m然后我把他们做连接
Select T.*,U.bb from
(select histdate,num,aa from hist
where histdate >= ...
and histdate <=...) T,(select histdate,num,bb from tbl
where histdate>=..
and histdate <= ..) Uwhere T.histdate = U.histdate
and T.num = U.num
连接查询后用时约10m
为什么我做了连接后,效率变得那么慢
hist中有海量数据,如果查询一周的记录要5分钟,一个月的就要半小时,hist中有个index:histdate
tbl数据较少没有index现在我有俩个查询语句,都是查询一天的数据
select histdate,num,aa from hist
where histdate >= ...
and histdate <=...
用时约0.1mselect histdate,num,bb from tbl
where histdate>=..
and histdate <= ..
用时约0.03m然后我把他们做连接
Select T.*,U.bb from
(select histdate,num,aa from hist
where histdate >= ...
and histdate <=...) T,(select histdate,num,bb from tbl
where histdate>=..
and histdate <= ..) Uwhere T.histdate = U.histdate
and T.num = U.num
连接查询后用时约10m
为什么我做了连接后,效率变得那么慢
解决方案 »
- oracle 字段过虑截取
- PL/SQL块中为什么定义varchar2变量必须加长度
- 各位帮忙看看,这个SQL应该怎么写
- 两小时左右出现一次 ORA-03113: 通信通道的文件结束
- orcale 触发器问题 请帮忙看看
- 关于Oracle环境变量
- 一个有关oracle分页sql的问题,在线等候。
- 这条SQL语句为什么不能执行啊~!~!~!
- 小问题,请高手指教???
- 求助,ORACLE传递参数的写法
- 初级问题:PL/SQL中过程和函数能够传入变长数组吗?
- java.sql.SQLException: Listener refused the connection with the following error:
(select histdate,num,aa from hist
where histdate >= ...
and histdate <=...) T,(select histdate,num,bb from tbl
where histdate>=..
and histdate <= ..) Uwhere T.histdate = U.histdate
and T.num = U.num
你看看2个子查询的数据量多少,数据流大做连接的话,还是比较慢的可以看看执行计划,看是否是连接上造成的时间消耗
U18行执行计划怎么看呢,我用的PL/SQL工具
Select T.*,U.bb from
(select histdate,num,aa from hist
where histdate >= ...
and histdate <=...) T,(select histdate,num,bb from tbl
where histdate>=..
and histdate <= ..) U
/*
where T.histdate = U.histdate
and T.num = U.num*/
我把连接条件注掉,300条结果,用时0.15m
为什么呢
Select T.histdate,T.num,T.aa,U.bb from
hist T,
tbl U
where
T.histdate >= ... and T.histdate <=...
and U.histdate >= ... and U.histdate <=...
and T.histdate = U.histdate
and T.num = U.num
看执行计划,或者更进一步做个autotrace或sqltrace,用数据说话