Unix Technical Forum

Simple query, very low performance

This is a discussion on Simple query, very low performance within the MySQL forums, part of the Database Server Software category; --> Newbie: I have only 60 000 rows within a tabe ("result"), but the following query takes very long: mysql> ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 07:54 AM
Bernhard Kornberger
 
Posts: n/a
Default Simple query, very low performance


Newbie: I have only 60 000 rows within a tabe ("result"), but the
following query takes very long:

mysql> SELECT MIN(received_time) as minimum FROM result;
+---------+
| minimum |
+---------+
| 0 |
+---------+
1 row in set (16.35 sec)


mysql> EXPLAIN SELECT MIN(received_time) as minimum FROM result;
+----+-------------+--------+------+---------------+------+---------+
| id | select_type | table | type | possible_keys | key | key_len |
ref | rows | Extra |
+----+-------------+--------+------+---------------+------+---------+
| 1 | SIMPLE | result | ALL | NULL | NULL | NULL |
NULL | 62895 | |
+----+-------------+--------+------+---------------+------+---------+

Here are the settings of my.conf:


# * Fine Tuning
key_buffer = 750M
max_allowed_packet = 2M
thread_stack = 128K
query_cache_limit = 2097152
query_cache_size = 16777216
query_cache_type = 1
replication.
log-bin = /var/log/mysql/mysql-bin.log
expire-logs-days = 20
max_binlog_size = 104857600
discouraged
skip-bdb


What should I check, where can I start to optimize?

best regards
Bernhard
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 07:54 AM
Paul Lautman
 
Posts: n/a
Default Re: Simple query, very low performance

Bernhard Kornberger wrote:
> Newbie: I have only 60 000 rows within a tabe ("result"), but the
> following query takes very long:
>
> mysql> SELECT MIN(received_time) as minimum FROM result;
> +---------+
>> minimum |

> +---------+
>> 0 |

> +---------+
> 1 row in set (16.35 sec)
>
>
> mysql> EXPLAIN SELECT MIN(received_time) as minimum FROM result;
> +----+-------------+--------+------+---------------+------+---------+
>> id | select_type | table | type | possible_keys | key | key_len |

> ref | rows | Extra |
> +----+-------------+--------+------+---------------+------+---------+
>> 1 | SIMPLE | result | ALL | NULL | NULL | NULL |

> NULL | 62895 | |
> +----+-------------+--------+------+---------------+------+---------+
>
> Here are the settings of my.conf:
>
>
> # * Fine Tuning
> key_buffer = 750M
> max_allowed_packet = 2M
> thread_stack = 128K
> query_cache_limit = 2097152
> query_cache_size = 16777216
> query_cache_type = 1
> replication.
> log-bin = /var/log/mysql/mysql-bin.log
> expire-logs-days = 20
> max_binlog_size = 104857600
> discouraged
> skip-bdb
>
>
> What should I check, where can I start to optimize?
>
> best regards
> Bernhard


I would suggest an index on the received_time column. That should save it
from having to examine all the values to see which is the smallest, as long
as mysql can figure out that for the MIN function it can use the index. I'm
sure it can, but if not you could change the query to:
SELECT receive_time as minimum FROM result ORDER BY receive_time LIMIT 1


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 07:54 AM
Paul Lautman
 
Posts: n/a
Default Re: Simple query, very low performance

Paul Lautman wrote:
> Bernhard Kornberger wrote:
>> Newbie: I have only 60 000 rows within a tabe ("result"), but the
>> following query takes very long:
>>
>> mysql> SELECT MIN(received_time) as minimum FROM result;
>> +---------+
>>> minimum |

>> +---------+
>>> 0 |

>> +---------+
>> 1 row in set (16.35 sec)
>>
>>
>> mysql> EXPLAIN SELECT MIN(received_time) as minimum FROM result;
>> +----+-------------+--------+------+---------------+------+---------+
>>> id | select_type | table | type | possible_keys | key | key_len |

>> ref | rows | Extra |
>> +----+-------------+--------+------+---------------+------+---------+
>>> 1 | SIMPLE | result | ALL | NULL | NULL | NULL |

>> NULL | 62895 | |
>> +----+-------------+--------+------+---------------+------+---------+
>>
>> Here are the settings of my.conf:
>>
>>
>> # * Fine Tuning
>> key_buffer = 750M
>> max_allowed_packet = 2M
>> thread_stack = 128K
>> query_cache_limit = 2097152
>> query_cache_size = 16777216
>> query_cache_type = 1
>> replication.
>> log-bin = /var/log/mysql/mysql-bin.log
>> expire-logs-days = 20
>> max_binlog_size = 104857600
>> discouraged
>> skip-bdb
>>
>>
>> What should I check, where can I start to optimize?
>>
>> best regards
>> Bernhard

>
> I would suggest an index on the received_time column. That should
> save it from having to examine all the values to see which is the
> smallest, as long as mysql can figure out that for the MIN function
> it can use the index. I'm sure it can, but if not you could change
> the query to: SELECT received_time as minimum FROM result ORDER BY
> received_time
> LIMIT 1

OK I just checked it and building the index and changing the query to
SELECT received_time as minimum FROM result ORDER BY received_time LIMIT 1
definitely seems the way to go.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 07:54 AM
Bernhard Kornberger
 
Posts: n/a
Default Re: Simple query, very low performance


> OK I just checked it and building the index and changing the query to
> SELECT received_time as minimum FROM result ORDER BY received_time LIMIT 1
> definitely seems the way to go.
>
>


Thank you, works perfectly!

best regards
Bernhard
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:22 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com