Answer the question
In order to leave comments, you need to log in
How to improve the performance of MYSQL stored functions?
Good afternoon. There is a stored function, it is maximally optimized for performance, no more squeezing. That's why it's written
DELIMITER $$
CREATE DEFINER=`root`@`127.0.0.1` FUNCTION `SORT_STR`(`string1` VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE sort VARCHAR(255);
DECLARE str1 VARCHAR(255);
DECLARE word VARCHAR(255);
CREATE TEMPORARY TABLE IF NOT EXISTS sort_t
(w VARCHAR(255));
SET str1 = LOWER(string1);
sub_str_loop: LOOP
SET word = SUBSTRING_INDEX(str1,' ', 1);
SET str1 = trim(replace(str1, word, ''));
INSERT INTO sort_t set w = word;
IF str1 = '' THEN
LEAVE sub_str_loop;
END IF;
END LOOP sub_str_loop;
select group_concat(`w` ORDER BY `w` asc SEPARATOR ' ') as words into sort from sort_t;
delete from sort_t;
RETURN sort;
END
UPDATE таблица SET колонка = null
386398 row(s) affected
Rows matched: 386398 Changed: 386398 Warnings: 0
17.659 sec
1 - 0.031
10 - 0.063
100 - 0.187
1000 - 3.775
10000 - 246.310
Answer the question
In order to leave comments, you need to log in
The whole thread of discussion and problem solving.
sqlinfo.ru/forum/viewtopic.php?pid=40185
Function called on select? If so, I would change the logic:
* Add a "words sorted" column to the source table
* Make an insert and update trigger that fills the "words sorted" column
* select flies, insert became slightly slower.
In general, the application server will not do such things faster? (for example php)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question