If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query response time

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-20-10, 07:55
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
query response time

hi
i just noticed something strange & i couldn't figure any reason out for it. i have 3 table each one has about 1 million record. every record in every one of tables have a timestamp field, none of them are index.
i wrote a query like this:
Code:
SELECT COUNT(*)AS num, '0' AS row, '0' AS col 
FROM t0, t1, t2
WHERE 1=1
AND t0.id = t1.id
AND t1.id = t2.id
AND t2.timestamp BETWEEN 'x' AND 'y'
GROUP BY '0', '0'
it's response time in phpMyAdmin is something around 2.5 sec, but when i change timestamp part to "AND t1.timestamp BETWEEN 'x' AND 'y'" (timestamp in t1 or in t0) response time goes up to 22 second!
i insist there isn't index on timestamp field.
any idea what's the reason for this huge response time difference?
__________________
Lyrics Database: www.shermani.com
Reply With Quote
  #2 (permalink)  
Old 11-20-10, 08:02
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
do an EXPLAIN on each query, paste the results here, and we'll try to, um, explain it to you

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-20-10, 08:39
bono56 bono56 is offline
Registered User
 
Join Date: May 2004
Posts: 133
first one with 2 sec res time:
Code:
id 	select_type table 	type 	possible_keys 	key 	key_len 	ref 	rows 	Extra
1 	SIMPLE 		t2 		ALL 	id 	NULL 		NULL 	NULL 		709875 	Using 	where
1 	SIMPLE 		t1 		eq_ref 	PRIMARY,id 		PRIMARY 4 			t2.id 	1 	 
1 	SIMPLE 		t0 		eq_ref 	PRIMARY 		PRIMARY 4 			t1.id 	1 		Using index

second one with over 20 sec res time:
Code:
id 	select_type table 	type 	possible_keys 	key 	key_len ref 	rows 	Extra
1 	SIMPLE 		t2 		index 	id 				car_id 	4 		NULL 	709875 	Using index
1 	SIMPLE 		t1 		eq_ref 	PRIMARY,id 		PRIMARY 4 		t2.id 	1 		Using where
1 	SIMPLE 		t0 		eq_ref 	PRIMARY 		PRIMARY 4 		t1.id 	1 		Using index
__________________
Lyrics Database: www.shermani.com
Reply With Quote
  #4 (permalink)  
Old 11-20-10, 09:12
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
thanks, but i can't figure out why the query that uses the index is slower

good luck
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 11-22-10, 09:49
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
looks like now it hits every row in the index and every row in the data page. Not sure why it would be THAT much slower though. I am guessing that t2 is the smallest of the three and that is why it is starting with that table, but no explanation why it would choose the index.
Reply With Quote
  #6 (permalink)  
Old 11-24-10, 15:05
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
There are two possible explanations for this:

1. The index on timestamp over time will become very inefficient due to the nature of the data which is sequential. A rebuild of the index will help optimize the size of the index and the access into the index.

2. The x and y values if they do not filter the content to a small subset this could end up being more inefficient with access to the index and subsequent access to the individual data rows. A full table scan in this case would be more efficient.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On