select a.fdstrscandate,b.fdstrimei,b.fdstrmodel from tbllocsecond a,
tbllocfirst b where a.fdstrboxno='DJ2003222' and a.fdstrimei=b.fdstrimei
说明:tbllocfirst表比tbllocsecond大很多,上面的查询非常慢。如果改成以下样子
select a.fdstrscandate,b.fdstrimei from tbllocsecond a,
tbllocfirst b where a.fdstrboxno='DJ2003222' and a.fdstrimei=b.fdstrimei即去掉了b.fdstrmodel则正常,b.fdstrimei是主键,但b.fdstrmodel也作了索引呀,为什么性能这么差(tbllocfirst表有几百万条记录)。该如何解决呢,请教!谢谢。
tbllocfirst b where a.fdstrboxno='DJ2003222' and a.fdstrimei=b.fdstrimei
说明:tbllocfirst表比tbllocsecond大很多,上面的查询非常慢。如果改成以下样子
select a.fdstrscandate,b.fdstrimei from tbllocsecond a,
tbllocfirst b where a.fdstrboxno='DJ2003222' and a.fdstrimei=b.fdstrimei即去掉了b.fdstrmodel则正常,b.fdstrimei是主键,但b.fdstrmodel也作了索引呀,为什么性能这么差(tbllocfirst表有几百万条记录)。该如何解决呢,请教!谢谢。
解决方案 »
- oracle安装在小型机上CPU利用率居高不下
- oracle结果显示
- 很简单的问题,希望大家帮帮忙
- 那位大侠详细讲讲alter system archive log current和alter system switch logfile的区别啊?
- 如何更改一个表的 primary key?
- 关于索引的问题,请各位老大指点下???
- 初学ORACLE,大家帮我看一下这个过程错在哪里
- update语句出错,不知道为什么,我看来看去是对的呀
- 快救命啊!oracle817在win2000 server服务器中起不来了,怎么回事啊,操作系统完好
- oracle的视图能否实现像sql server的视图一样的左联接或右联接或full
- oracle查询问题
- 求oracle列动态交叉表的写法
where a.fdstrimei=b.fdstrimei and a.fdstrboxno='DJ2003222';
tbllocfirst b where a.fdstrboxno='DJ2003222' and a.fdstrimei=b.fdstrimei
和
select fdstrscandate,fdstrimei from tbllocsecond
where fdstrboxno='DJ2003222'
有什么不同吗?select a.fdstrscandate,b.fdstrimei,b.fdstrmodel from tbllocsecond a,
tbllocfirst b where a.fdstrboxno='DJ2003222' and a.fdstrimei=b.fdstrimei
用到了tbllocfirst表肯定会慢的
select a.fdstrscandate,b.fdstrimei,b.fdstrmodel from tbllocfirst b,
tbllocsecond a where a.fdstrimei=b.fdstrimei and a.fdstrboxno='DJ2003222'
还有就是这两张表分别有哪些索引,主键是怎样定义的。
tbllocfirst b where a.fdstrboxno='DJ2003222' and a.fdstrimei=b.fdstrimei
和
select fdstrscandate,fdstrimei from tbllocsecond
where fdstrboxno='DJ2003222'
有什么不同吗?
-----
可能会不同,我想错了
我加了hint语句后,在1秒钟内可以完成/*+ rule */有一点我不太明白,顺便帮忙解释一下:按主键查询时应该是先从主键找到该行,然后从该行中再找其中某列,为什么不同的列有这么大的不同呢?请赐教!
因为查询的列的不同,oracle会可能采用不同的索引,选择那张表做主表,或者决定是否用表扫描。因此查询的速度就会有差异。
例如,表t有字段ID和NAME两个字段,有一索引idx1是只按NAME建的,在对表做过表分析后,执行
select name from t where name like '%分公司%'
oracle会采用索引快速查找(INDEX FAST FULL SCAN)来执行该语句。如果是执行
select id,name from t where name like '%分公司%'
则是执行的表扫描。
极有可能是两表关联时的join操作扫表顺序不同造成的。我优化过几个SQL,只是简单地调整循环嵌套连接中内外表的顺序,就将时间由几十秒降到零点几秒。