如何加速这个sql速度?

[复制链接]
查看11 | 回复6 | 2010-3-1 11:08:33 | 显示全部楼层 |阅读模式
我的一个sql的核心一段如下
select wpt.act_end_date
from work_plan_master wpm, work_plan_tasks wpt
where wpt.plan_id = wpm.plan_id;
其中work_plan_tasks .plan_id是该表的外键。
explain plan表明对work_plan_tasks 进行了full table scans,该表较大,导致速度很慢。
记录统计信息如下:
select count(*)
from work_plan_master -- 208633
select count(*) from work_plan_tasks; -- 1477836
select count(distinct plan_id) from work_plan_tasks -- 208631
想请教两个问题:
1,听说因为oracle的表连接机制,外表是进行full table scans的,对否?
2,我能否停用foreign key, 根据统计,plan_id在work_plan_tasks 内分布值在14%左右,能否建bitmap index来提速?
thank!!!
回复

使用道具 举报

千问 | 2010-3-1 11:08:33 | 显示全部楼层
两表上是否有索引。
回复

使用道具 举报

千问 | 2010-3-1 11:08:33 | 显示全部楼层
将执行计划贴出来看看
回复

使用道具 举报

千问 | 2010-3-1 11:08:33 | 显示全部楼层
先加上索引试试,或者把表先分析一下
回复

使用道具 举报

千问 | 2010-3-1 11:08:33 | 显示全部楼层
最初由 Jervis 发布
[B]我的一个sql的核心一段如下
select wpt.act_end_date
from work_plan_master wpm, work_plan_tasks wpt
where wpt.plan_id = wpm.plan_id;
其中work_plan_tasks .plan_id是该表的外键。
explain plan表明对work_plan_tasks 进行了full table scans,该表较大,导致速度很慢。
记录统计信息如下:
select count(*)
from work_plan_master -- 208633
select count(*) from work_plan_tasks; -- 1477836
select count(distinct plan_id) from work_plan_tasks -- 208631
想请教两个问题:
1,听说因为oracle的表连接机制,外表是进行full table scans的,对否?
2,我能否停用foreign key, 根据统计,plan_id在work_plan_tasks 内分布值在14%左右,能否建bitmap index来提速?
thank!!! [/B]

建Bitmap index不好。
act_end_date、plan_id建成组合索引。
用不用全表扫描,还得很你的SQL做什么的。。。
回复

使用道具 举报

千问 | 2010-3-1 11:08:33 | 显示全部楼层
act_end_date、plan_id建成组合索引,work_plan_tasks应该就不会full table scans
回复

使用道具 举报

千问 | 2010-3-1 11:08:33 | 显示全部楼层
谢谢各位。
两表都有索引,plan_id是work_plan_masks的primary key, 也是work_plan_tasks的foreign key.
建组合索引是无助解决问题的。根据我观察,外表关联主表,都是是外表full table scans,不过不肯定是否为规律。
因为库是database warehouse,所以我用别的方法解决了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行