HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Optimize queries from MySQL SP/Triggers/Functions

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
functionsmysqloptimizequeriesfromtriggers

Problem

I have to investigate a MySQL Production server,While investigating I found a DELETE query in "SHOW PROCESSLIST" which was taking more than 400 second in preparing state, I tried to find the query in slow log but i was unable to find the query in slow log.

```
mysql> show full processlist;
+------+-----------------+---------------------+-----------+---------+------+-----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------+-----------------+---------------------+-----------+---------+------+-----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2 | event_scheduler | localhost | NULL | Daemon | 204 | Waiting for next activation | NULL |
| 7229 | root | 192.168.1.178 | mydb

Solution

You have actually asked two questions:

-
"If a query is written in MySQL SP/Triggers/Functions/Events is slow, it will not be logged into slow log file"

Answer: it will not be logged in standard MySQL server. Do take a look at the Percona Server extension for the slow log: in particular look at the log_slow_sp_statements configuration variable. It does what you want: the slow queries within routines are logged. Note that this does not apply to triggers.

-
"Do we need to optimize each SP/Triggers/Functions/Events individually?"

Answer: well, of course. Each and every query needs to be as optimized as you can, depending on your requirements. A routine is not a "magic solution" that causes inner queries to run faster...

Context

StackExchange Database Administrators Q#55809, answer score: 5

Revisions (0)

No revisions yet.