发现一个SQL执行很慢,如下:
select
*
from
rmes.r_wip_tracking_t wt, cmes.c_material_t m
where
m.material_type
=
1
and
(m.material_spec
like
'
L%
'
or
m.material_spec
like
'
C%
'
)
and
wt.model_id
=
m.material_id
AND
WT.sn
>=
'
1073H2H72270002
'
and
WT.sn
<=
'
1073H2H72270002
'
计划分析后,发现是都有走索引。
统计两个表如下:
1.R_WIP_TRACKING_T: 总共有3580030记录,其中用SN有索引,并且SN在表中唯一
2.c_material_t 总共有512条数据,material_type是外键有NORMAL索引,material_spec无索引
有一点发现,如果去掉material_type=1的SQL会变很快,说明是material_type的问题
在512记录中发现
| MATERIAL_TYPE | COUNT |
| 0 | 196 |
| 1 | 276 |
| 2 | 8 |
| 3 | 10 |
| 4 | 8 |
| 5 | 13 |
| 7 | 1 |
执行:
drop index FK_TYPE;
create bitmap index FK_TYPE on C_MATERIAL_T (MATERIAL_TYPE) tablespace CMES;
就把SQL的运行时间从89秒降低到了0.15秒

