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

MySQL slow query log: huge query time, no lock time, minuscule number of rows scanned

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

Problem

I have a slow query log item with the following:

Query_time: 55  Lock_time: 0  Rows_sent: 739  Rows_examined: 739


No one in my group can explain it besides a guess about packet loss. Is there a common cause or set of causes for result like the above?

Solution

I'm going out on a limb here, but did you do an 'EXPLAIN' on this query?

If not, run "EXPLAIN" to see what the execution plan is. This will give you hints on optimization or indexing.

E.g. SOMETHING LIKE

EXPLAIN SELECT a.field1,b.field1 FROM tableA a LEFT JOIN tableB b ON b.a_id = a.id;


The result will be a nicely formatted report.

You may find there's unnecessary complexity in the query that can be pushed to the application or just factored out.

Code Snippets

EXPLAIN SELECT a.field1,b.field1 FROM tableA a LEFT JOIN tableB b ON b.a_id = a.id;

Context

StackExchange Database Administrators Q#5048, answer score: 3

Revisions (0)

No revisions yet.