【MYSQL】state狀態converting HEAP to MyISAM

小亮520cl發表於2017-09-06
背景:機房遷移,原報表系統在新的db上出報表非常慢

1.檢視連線狀態
  1. mysql> show full processlist;
  2. +--------+-----------------+---------------------+----------+---------+---------+-----------------------------------------------------------------------------+-----------------------+
  3. | Id | User | Host | db | Command | Time | State | Info |
  4. +--------+-----------------+---------------------+----------+---------+---------+-----------------------------------------------------------------------------+-----------------------+
  5. | 1 | event_scheduler | localhost | NULL | Daemon | 2247681 | Waiting on empty queue | NULL |
  6. | 121456 | system user | | NULL | Connect | 784383 | Waiting for master to send event | NULL |
  7. | 121457 | system user | | NULL | Connect | 1 | Slave has read all relay log; waiting for the slave I/O thread to update it | NULL |
  8. | 121468 | ecejadmin | 192.168.2.104:42497 | ecejdbv3 | converting HEAP to MyISAM | 1 | | 複雜sql                 |
  9. | 121469 | ecejadmin | 192.168.2.10:54423 | ecejdbv3 | converting HEAP to MyISAM | 2 | | 複雜sql |
  10. | 121470 | ecejadmin | 192.168.2.12:9386 | ecejdbv3 | converting HEAP to MyISAM | 1 | | 複雜sql |
  11. | 121471 | ecejadmin | 192.168.2.104:63937 | ecejdbv3 | converting HEAP to MyISAM | 2 | | 複雜sql

報表sql狀態如上

2.處理過程
  1. 1.在終端裡set profiling=1;
  2. 2.輸入要調整的SQL語句,比如複雜sql;
  3. 3.輸入show profiles;看看剛才那條語句的ID 用於後面分析
  4. 4.show profile for query 2;
  5. 5.show profile block io,cpu for query 2;
  6. 6.show profile cpu,block io,memory,swaps,context switches,source for query 5;
  7. 7.透過上面的一些查詢 大體可以看出這條SQL語句執行的時候哪些地方佔用的時間太大了。這次測試看到的是Copying to tmp table on disk和converting HEAP to MyISAM佔有的時間太多。網上查了一下發現可以修改一下tmp_table_size和max_heap_table_size兩個引數來調整,使得大資料量的查詢時不用將結果集複製到物理磁碟。這樣時間就爭取過來了




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2144585/,如需轉載,請註明出處,否則將追究法律責任。

相關文章