sql - MySQL: Any suggestions to improve best match Stored Procedures -
sql - MySQL: Any suggestions to improve best match Stored Procedures -
for project working on have scan key best match. these scan causing lot of load on our test system. body thought how can improve this? tried temporary tables , cursors.
an illustration of code using:
set keylength = (length(key)-1); while keylength >=1 select count(*) resultcount keytable screeningkey = (select substring(key)-,1,keylength)); if (0 < resultcount) select screeningkey bestmatchscreeningkey keytable , screeningkey = (select substring(key)-,1,keylength)); /*go step4*/ leave step4; end if; set keylength = keylength-1; end while;
instead of using select count(*) utilize if exists. if exists can stop scanning finds match, while count(*) needs go through entire table tally count.
so, end like: (i don't utilize much mysql, i'm not sure on syntax , copy-pasted syntax doesn't quite right me...)
set keylength = (length(key)-1); while keylength >=1 if exists (select * keytable screeningkey = (select substring(key)-,1,keylength))) select substring(key)-,1,keylength bestmatchscreeningkey; /*go step4*/ leave step4; end if; set keylength = keylength-1; end while; mysql sql stored-procedures range
Comments
Post a Comment