Hi.
I need a little help to optimize requests on a table, and I have no
idea how to do it (I optimized already a lot other table, but this one
is a pain). My table looks like :
CREATE TABLE comments (
id int(11) NOT NULL auto_increment,
subject varchar(80) NOT NULL default '',
timestamp timestamp(14) NOT NULL,
user_id int(6) NOT NULL default '1',
com_parent int(11) NOT NULL default '0',
res_type int(5) NOT NULL default '1',
PRIMARY KEY (id),
KEY id (id),
KEY news_id (news_id),
KEY user_id (user_id),
KEY com_parent (com_parent),
KEY res_type (res_type),
KEY timestamp (timestamp),
KEY thread_id (thread_id)
) TYPE=MyISAM PACK_KEYS=1;
It has about 500.000 entries. A simple select like :
SELECT id,subject FROM commentsnew WHERE user_id=9790 AND res_type != 3
ORDER BY id DESC LIMIT 20;
takes about 4 seconds !! :( If I run it fews times, after 3 times it
goes ok (0.03). Any idea to improve it ? I tried to go in InnoDB but it
goes as slow as on MyISAM. a 'DESC' on the request shows :
+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
| comments | ref | user_id,user_id _restypeid | user_id | 4 |
const | 1602 | where used; Using filesort |
+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
For information we did setup mysql with :
set-variable = key_buffer=32M
set-variable = max_allowed_pac ket=2M
set-variable = thread_stack=2M
set-variable = table_cache=102 4
set-variable = sort_buffer=4M
set-variable = record_buffer=2 M
set-variable = join_buffer=2M
set-variable = tmp_table_size= 2M
set-variable = flush_time=0
							
						
					I need a little help to optimize requests on a table, and I have no
idea how to do it (I optimized already a lot other table, but this one
is a pain). My table looks like :
CREATE TABLE comments (
id int(11) NOT NULL auto_increment,
subject varchar(80) NOT NULL default '',
timestamp timestamp(14) NOT NULL,
user_id int(6) NOT NULL default '1',
com_parent int(11) NOT NULL default '0',
res_type int(5) NOT NULL default '1',
PRIMARY KEY (id),
KEY id (id),
KEY news_id (news_id),
KEY user_id (user_id),
KEY com_parent (com_parent),
KEY res_type (res_type),
KEY timestamp (timestamp),
KEY thread_id (thread_id)
) TYPE=MyISAM PACK_KEYS=1;
It has about 500.000 entries. A simple select like :
SELECT id,subject FROM commentsnew WHERE user_id=9790 AND res_type != 3
ORDER BY id DESC LIMIT 20;
takes about 4 seconds !! :( If I run it fews times, after 3 times it
goes ok (0.03). Any idea to improve it ? I tried to go in InnoDB but it
goes as slow as on MyISAM. a 'DESC' on the request shows :
+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
| comments | ref | user_id,user_id _restypeid | user_id | 4 |
const | 1602 | where used; Using filesort |
+----------+------+---------------------------+---------+---------+-------+------+----------------------------+
For information we did setup mysql with :
set-variable = key_buffer=32M
set-variable = max_allowed_pac ket=2M
set-variable = thread_stack=2M
set-variable = table_cache=102 4
set-variable = sort_buffer=4M
set-variable = record_buffer=2 M
set-variable = join_buffer=2M
set-variable = tmp_table_size= 2M
set-variable = flush_time=0
 
	
Comment