我的過程查詢需要19.546s,您可以在下面的快照底部看到。你可以看到總數據是60370項。程序查詢花費很多時間,19.546s很長。如何優化程序方法?
那麼,有沒有優化我的程序的方法?這是我的程序:
BEGIN
declare icount int default 0;
declare exit handler for SQLEXCEPTION set out_a=1;
select count(*) into icount from P01 where P0101=in_a;
if icount=0 THEN
set out_a=1;
set out_b=0;
set out_c='';
set out_d='';
ELSE
set out_a=0;
select P0106,P0107,P0108 into out_b,out_c,out_d from P01 where P0101=in_a;
if in_b=1 then
select P0202,P0203,P0204,P0205 from P02 where P0201=in_a and P0204=out_b+1 order by P0202;
ELSE
select P0202,P0203,P0204,P0205 from P02 where P0201=in_a and P0204>=out_b+1 order by P0202;
end if;
end if;
END
有沒有辦法縮短程序花費的時間?
編輯
如果我詢問我的表p02
,將斥資20 + S:
select * from p02;
所以,這裏也許這個問題?
對這些查詢運行'EXPLAIN',找到您缺少索引的位置。 – miken32
@ miken32我更新了我的問題,可以看出,查詢表格還需要很長時間。 –