That is good and fast. Now we create a trigger which will call our dummy func1():
- CREATE DEFINER=`root`@`localhost` TRIGGER `test`.`form_AFTER_UPDATE`
- AFTER UPDATE ON `form`
- FOR EACH ROW
- BEGIN
- declare r int default 0;
- select func1() into r;
- END
Now repeat the update. Remember: it does not change the result of the update as we do not really do anything inside the trigger.
- mysql> update form set form_created_date = NOW() where form_id > 5000;
- Query OK, 65536 rows affected (0.90 sec)
- Rows matched: 65536 Changed: 65536 Warnings: 0
Just adding a dummy trigger will add 2x overhead: the next trigger, which does not even run a function, introduces a slowdown:
- CREATE DEFINER=`root`@`localhost` TRIGGER `test`.`form_AFTER_UPDATE`
- AFTER UPDATE ON `form`
- FOR EACH ROW
- BEGIN
- declare r int default 0;
- END
- mysql> update form set form_created_date = NOW() where form_id > 5000;
- Query OK, 65536 rows affected (0.52 sec)
- Rows matched: 65536 Changed: 65536 Warnings: 0
Now, lets use func3 (which has "dead" code and is equivalent to func1):
- CREATE DEFINER=`root`@`localhost` TRIGGER `test`.`form_AFTER_UPDATE`
- AFTER UPDATE ON `form`
- FOR EACH ROW
- BEGIN
- declare r int default 0;
- select func3() into r;
- END
- mysql> update form set form_created_date = NOW() where form_id > 5000;
- Query OK, 65536 rows affected (1.06 sec)
- Rows matched: 65536 Changed: 65536 Warnings: 0
However, running the code from the func3 inside the trigger (instead of calling a function) will speed up the update:
- CREATE DEFINER=`root`@`localhost` TRIGGER `test`.`form_AFTER_UPDATE`
- AFTER UPDATE ON `form`
- FOR EACH ROW
- BEGIN
- declare r int default 0;
- IF 1=2 THEN
- select levenshtein_limit_n('test finc', 'test func', 1) into r;
- END IF;
- IF 2=3 THEN
- select levenshtein_limit_n('test finc', 'test func', 10) into r;
- END IF;
- IF 3=4 THEN
- select levenshtein_limit_n('test finc', 'test func', 100) into r;
- END IF;
- IF 4=5 THEN
- select levenshtein_limit_n('test finc', 'test func', 1000) into r;
- END IF;
- END
- mysql> update form set form_created_date = NOW() where form_id > 5000;
- Query OK, 65536 rows affected (0.66 sec)
- Rows matched: 65536 Changed: 65536 Warnings: 0
Memory Allocation (编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|