【发布时间】:2017-09-15 23:44:02
【问题描述】:
我只是在进程列表中发现了很多“复制到 tmp 表”的查询状态,这些查询运行时间超过 40 秒。
服务器详情:
Server: Localhost via UNIX socket
Server version: 5.5.40-0ubuntu0.12.04.1-log
my.cnf values:
key_buffer_size = 134217728
query_cache_limit = 2097152;
max_heap_table_size = 536870912;
tmp_table_size = 536870912;
concurrent_insert AUTO
low_priority_updates OFF
table_open_cache = 12288;
long_query_time = 2;
max_connections = 300
join_buffer_size=1048576
interactive_timeout=300
wait_timeout=300
innodb_buffer_pool_size =2G;
log-queries-not-using-indexes = OFF
“SHOW STATUS LIKE 'qc%'”的结果:
Qcache_free_blocks 12334
Qcache_free_memory 42059504
Qcache_hits 330467210
Qcache_inserts 946786273
Qcache_lowmem_prunes 2815011
Qcache_not_cached 177691822
Qcache_queries_in_cache 21886
Qcache_total_blocks 56201
请提出更好的值。
如果有什么需要请告诉我
(来自 cmets)
SELECT myid,inb_id,message,date,STATUS
FROM messages
WHERE youid =userid
AND STATUS =3
GROUP BY myid
ORDER BY date DESC
LIMIT 0 , 15
CREATE TABLE messages (
myid int(10) NOT NULL,
youid int(10) NOT NULL,
message text NOT NULL,
date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
inb_id int(11) NOT NULL AUTO_INCREMENT,
readed varchar(30) NOT NULL,
status int(10) NOT NULL,
delete int(11) NOT NULL,
today varchar(20) NOT NULL,
dupdate varchar(20) NOT NULL,
PRIMARY KEY (inb_id),
KEY Idxdate (date),
KEY Idxyouid (youid),
KEY Idxdupdate (dupdate),
KEY Idxid (myid),
KEY Idxmyid (myid,youid),
KEY Idxyouread (youid,readed),
KEY Idxyouid_status (youid,status),
KEY Idxyoudt (youid,status,date)
) ENGINE=InnoDB AUTO_INCREMENT=165893279 DEFAULT CHARSET=latin1
【问题讨论】:
-
考虑在 tmp 表上阅读一些内容:percona.com/blog/2007/01/19/…
-
考虑使用 ramdisk 来加快速度..
标签: mysql optimization