加入收藏 | 设为首页 | 会员中心 | 我要投稿 常州站长网 (https://www.0519zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

为什么MySQL存储过程、函数和触发器对性能不好

发布时间:2018-08-19 15:53:15 所属栏目:MySql教程 来源:佚名
导读:副标题#e# 技术沙龙 | 邀您于8月25日与国美/AWS/转转三位专家共同探讨小程序电商实战 MySQL存储过程、函数和触发器是应用程序开发人员的诱人构造。但是,正如我所发现的,使用MySQL存储例程会影响数据库性能。由于不能完全确定在客户访问期间看到了什么,我

As we can see, func3 (with four dead code calls that will never be executed, otherwise identical to func1) runs almost 3x slower compared to func1(); func3_nope() is identical in terms of response time to func3().

Visualizing All System Calls From Functions

To figure out what is happening inside the function calls, I used performance_schema/sys schema to create a trace with ps_trace_thread() procedure.

1.Get the thread_id for the MySQL connection:

  1. mysql> select THREAD_ID from performance_schema.threads where processlist_id = connection_id();  
  2. +-----------+  
  3. | THREAD_ID |  
  4. +-----------+  
  5. |        49 |  
  6. +-----------+  
  7. 1 row in set (0.00 sec)  

2.Run ps_trace_thread in another connection passing the thread_id=49:

  1. mysql> CALL sys.ps_trace_thread(49, concat('/var/lib/mysql-files/stack-func1-run1.dot'), 10, 0, TRUE, TRUE, TRUE);  
  2. +--------------------+  
  3. | summary            |  
  4. +--------------------+  
  5. | Disabled 0 threads |  
  6. +--------------------+  
  7. 1 row in set (0.00 sec)  
  8. +---------------------------------------------+  
  9. | Info                                        |  
  10. +---------------------------------------------+  
  11. | Data collection starting for THREAD_ID = 49 |  
  12. +---------------------------------------------+  
  13. 1 row in set (0.00 sec)  

3.At that point I switched to the original connection (thread_id=49) and run:

  1. mysql> select func1();  
  2. +---------+  
  3. | func1() |  
  4. +---------+  
  5. |       0 |  
  6. +---------+  
  7. 1 row in set (0.00 sec)  

(编辑:常州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读