MySQL Forums
Forum List  »  Optimizer & Parser

How to optimize this trigger?
Posted by: li grewat
Date: June 21, 2007 08:18PM

In a project ,I have written a trigger before insert. However, I found it is not ideal,It is too slow,How should I optimize this trigger?
The most important is that in four select ,there are the same condition "maxrid-rid<1000", can it be optimized ? The relational sql script is as follows:
-------------- BEGIN -------------------------
BEGIN
DECLARE snumc_c CURSOR FOR select count(dstaddr) from tcpflow where srcaddr=NEW.srcaddr and maxrid-rid<1000;
DECLARE EXIT HANDLER FOR NOT FOUND SET NEW.sipcdip =0;
OPEN snumc_c;
FETCH snumc_c INTO num;
set NEW.sipcdip =num;
CLOSE snumc_c;
END;

BEGIN
DECLARE dnumc_c CURSOR FOR select count(srcaddr) from tcpflow where dstaddr=NEW.dstaddr and maxrid-rid<1000;
DECLARE EXIT HANDLER FOR NOT FOUND SET NEW.dipcsip =0;
OPEN dnumc_c;
FETCH dnumc_c INTO num;
set NEW.dipcsip =num;
CLOSE dnumc_c;
END;

BEGIN
DECLARE spnumc_c CURSOR FOR select count(dstaddr) from tcpflow where srcport=NEW.srcport and maxrid-rid<1000;
DECLARE EXIT HANDLER FOR NOT FOUND SET NEW.sportcdip =0;
OPEN spnumc_c;
FETCH spnumc_c INTO num;
set NEW.sportcdip =num;
CLOSE spnumc_c;
END;

BEGIN
DECLARE dpnumc_c CURSOR FOR select count(srcaddr) from tcpflow where dstport=NEW.dstport and maxrid-rid<1000;
DECLARE EXIT HANDLER FOR NOT FOUND SET NEW.dportcsip =0;
OPEN dpnumc_c;
FETCH dpnumc_c INTO num;
set NEW.dportcsip =num;
CLOSE dpnumc_c;
END;

--------------------END -----------------------------------
Can it be query only once for the condition "maxrid-rid<1000 " and then the four sentence can use it ?
Thanks very much

Options: ReplyQuote


Subject
Views
Written By
Posted
How to optimize this trigger?
4460
June 21, 2007 08:18PM
2209
June 22, 2007 05:49AM
2180
June 24, 2007 06:22PM


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.