查询突然变慢,求高手看看
sql server2000 fact_pmrelate 表删除后,重新从sql 2005 fact_pmrelate导入数据800W条记录,重新建立主键(FPID,FMID,OrgNo)复合主键,及索引index_define_time(define_tie),index_define_by(define_by),跟原来表一样,但查询变慢了,现在需要三四分钟,原来只要十秒,求高手看看,不知何故
后又用DBCC reindex(fact_pmrelate,'','0') 以及更新该表统计信息,都没效果,另Import_Spread_Pmrelate 没有主键,fpid为非空。
下面语句变慢
select fpid,fmid,-8 info_type,
define_time
from Import_Spread_Pmrelate e
where not exists (select 1 from fact_pmrelate t where t.fpid = e.fpid)
group by fpid,fmid,define_time
[解决办法]
-- 建议:
-- 1.在fact_pmrelate表fpid字段上建索引.
create index ix_fact_pmrelate_fpid on fact_pmrelate(fpid)
-- 2.在Import_Spread_Pmrelate表fpid字段上建索引.
create index ix_Import_Spread_Pmrelate_fpid on Import_Spread_Pmrelate(fpid)
-- 3.查询语句修改为如下试试.
select e.fpid,e.fmid,-8 'info_type',e.define_time
from Import_Spread_Pmrelate e
left join fact_pmrelate t on e.fpid=t.fpid
where t.fpid is null
group by e.fpid,e.fmid,e.define_time