mysql - Select from table is slow -
my problem is: simple select query takes long time (3 minutes).
structure:
mysql> show create table seventhcont_exceptionreport; seventhcont_exceptionreport | create table `seventhcont_exceptionreport` ( `id` int(11) not null auto_increment, `body_html` longtext not null, `datetime_created` datetime not null, `subject` varchar(256) not null, `host` varchar(128) not null, `exc_value` varchar(512) default null, primary key (`id`) ) engine=myisam auto_increment=74607 default charset=utf8 | rows count:
mysql> select count(*) seventhcont_exceptionreport; +----------+ | count(*) | +----------+ | 7064 | +----------+ 1 row in set (0.00 sec) query 1 (normal):
mysql> select id, datetime_created seventhcont_exceptionreport order id limit 100 offset 6000; ... 100 rows in set (0.30 sec) query 2 (very slow):
mysql> select id, datetime_created seventhcont_exceptionreport order id limit 100 offset 7000; ... 63 rows in set (3 min 40.56 sec) !!! 3 minutes , 40 sec.
why?
update
explain query 1:
mysql> explain select id, datetime_created seventhcont_exceptionreport order id limit 100 offset 6000; +----+-------------+-----------------------------+-------+---------------+---------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | | +----+-------------+-----------------------------+-------+---------------+---------+---------+------+------+-------+ | 1 | simple | seventhcont_exceptionreport | index | null | primary | 4 | null | 6100 | | +----+-------------+-----------------------------+-------+---------------+---------+---------+------+------+-------+ 1 row in set (0.00 sec) explain query 2:
mysql> explain select id, datetime_created seventhcont_exceptionreport order id limit 100 offset 7000; +----+-------------+-----------------------------+------+---------------+------+---------+------+------+----------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | | +----+-------------+-----------------------------+------+---------------+------+---------+------+------+----------------+ | 1 | simple | seventhcont_exceptionreport | | null | null | null | null | 7067 | using filesort | +----+-------------+-----------------------------+------+---------------+------+---------+------+------+----------------+ 1 row in set (0.00 sec) update
analyze table:
mysql> analyze table seventhcont_exceptionreport; +--------------------------------+---------+----------+----------+ | table | op | msg_type | msg_text | +--------------------------------+---------+----------+----------+ | 7k.seventhcont_exceptionreport | analyze | status | ok | +--------------------------------+---------+----------+----------+ 1 row in set (2.51 sec)
i no mysql specialist, might able point in right direction.
in first query, can see in explain plan, index access used. in contrast, second query, can see non-index access performed (type index vs all). also, can see mysql using using filesort.
this means mysql cannot perform sort operation on index , therefore performing on data itself. because sort buffer small (also see https://www.percona.com/blog/2009/03/05/what-does-using-filesort-mean-in-mysql/).
therefore, try increase size of sort buffer (soft_buffer_size).
Comments
Post a Comment