Jump to content

Confused - Query Time


jaymc

Recommended Posts

I have been watching the mysql process list and often find some queries taking 50 seconds

 

I then copy that query and run it on a test server and it takes 0.3 seconds

 

There is no cache involved as that query has never been run before on the test server

 

Can you think of a reason why a query can be instant and then another time take 50 seconds.

 

By the way, this query was the highest running one, so its not as if there was a query running ahead of it (51 seconds) Which had locked the table.

 

Table is InnoDB

 

Perhaps its not reading something from memory, so resorts direct to disk hence 50 seconds rather than 0.3

 

Please advise why this may happen

Link to comment
Share on other sites

EXPLAIN  SELECT SQL_NO_CACHE f.user, f.friend, f.gender, f.x, f.timestamp, c.propic AS image

FROM friends f

INNER JOIN cache c ON f.friend = c.username

WHERE f.user = 'jaymc'

AND f.gender = 'Male'

ORDER BY f.x DESC , f.timestamp DESC

LIMIT 0 , 10

 

id 	select_type 	table 	type 	possible_keys 	key 	key_len 	ref 	rows 	Extra 
1  	SIMPLE  	f  	ref  	user,friend,user_2  	user_2  	27  	const  	2994  	Using where; Using index; Using filesort
1 	SIMPLE 	c 	eq_ref 	PRIMARY 	PRIMARY 	27 	mysql.f.friend 	1 

 

5 million rows by the way

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.