MySQL Forums
Forum List  »  Stored Procedures

Why this is slow ?
Posted by: hello world
Date: December 01, 2005 03:08PM

when i use this function in a loop for 111 times , the machine seems like hanging. why ? there is index for all tables. any better idea in performance.

Create function f_Payment (v_Agent varchar(3), v_Comp varchar(100) ) returns varchar(100)
BEGIN

declare a1 varchar(20);
declare a2 varchar(20);
declare a3 varchar(20);

declare v_Result varchar(100);

select sum(amount) into a1 from reload where agentid=v_Agent and compid=v_Comp;
select sum(amount) into a2 from payment where agentid=v_Agent and compid=v_Comp;
select sum(callcost) into a3 from cdr where agentid=v_Agent and compid=v_Comp;

IF(a1 IS NULL) THEN
select 0 into a1;
select concat(a1, "," , a2, "," , a3) into v_Result;
ELSE
select concat(a1, "," , a2, "," , a3) into v_Result;
END IF;

IF(a2 IS NULL) THEN
select 0 into a2;
select concat(a1, "," , a2, "," , a3) into v_Result;
ELSE
select concat(a1, "," , a2, "," , a3) into v_Result;
END IF;

IF(a3 IS NULL) THEN
select 0 into a3;
select concat(a1, "," , a2, "," , a3) into v_Result;
ELSE
select concat(a1, "," , a2, "," , a3) into v_Result;
END IF;


return v_Result;

END;

Options: ReplyQuote


Subject
Views
Written By
Posted
Why this is slow ?
3064
December 01, 2005 03:08PM
1367
December 01, 2005 04:16PM
1712
December 02, 2005 03:38AM
1672
December 02, 2005 05:13AM
1626
December 02, 2005 12:26PM
1705
December 02, 2005 09:42AM
1648
December 02, 2005 02:18PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.