mysql性能问题小解 Converting HEAP to MyIsam create_myisa

Wesley13
• 阅读 532

安定北京 被性能测试困扰了N天,实在没想法去解决了,今天又收到上级的命令说 安定北京 要解决,无奈!把项目组唯一的DBA辞掉了,现在所以数据库的问题都得自己来处理:( 不知道上边人怎么想的。而且更不知道怎 安定北京 么想的是居然会把应用部属在虚拟主机上!唉。。。 不唠叨了 说说处理过程吧: 1.在终端里set profiling=1; 2.输入要调整的SQL语句,比如select * from table1; 3.输入show profiles;看看刚才那条语句的ID 用于后面分析 4.show profile for query 2; 5.show profile block io,cpu for query 2; 6.show profile cpu,block io,memory,swaps,context switches,source for query 5; 7.通过上面的一些查询 大体可以看出这条SQL语句执行的时候哪些地方占用的时间太大了。这次测试看到的是Copying to tmp table on disk和converting HEAP to MyISAM占有的时间太多。网上查了一下发现可以修改一下tmp_table_size和max_heap_table_size两个参数来调整,使得大数据量的查询时不用将结果集拷贝到物理磁盘。这样时间就争取过来了 对了 MYSQL有个好用的命令可以分析一条SQL的结构,可以查到这个查询是否使用到索引等。直接explain select * from table1就行了 +--------------------------------+------------+------------+------------+-------------------+---------------------+--------------+---------------+-------+---------------------------+---------------+-------------+ | Status                         | Duration   | CPU_user   | CPU_system | Context_voluntary | Context_involuntary | Block_ops_in | Block_ops_out | Swaps | Source_function           | Source_file   | Source_line | +--------------------------------+------------+------------+------------+-------------------+---------------------+--------------+---------------+-------+---------------------------+---------------+-------------+ | checking query cache for query | 0.00001100 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | send_result_to_client     | sql_cache.cc  |        1094 | | Opening tables                 | 0.00023400 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | open_tables               | sql_base.cc   |        2106 | | System lock                    | 0.00002800 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | mysql_lock_tables         | lock.cc       |         153 | | Table lock                     | 0.00001300 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | mysql_lock_tables         | lock.cc       |         162 | | optimizing                     | 0.00022700 | 0.00099900 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | optimize                  | sql_select.cc |         617 | | statistics                     | 0.00002900 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | optimize                  | sql_select.cc |         773 | | preparing                      | 0.00012800 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | optimize                  | sql_select.cc |         783 | | Creating tmp table             | 0.00003400 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | optimize                  | sql_select.cc |        1206 | | executing                      | 0.00003100 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | exec                      | sql_select.cc |        1407 | | Copying to tmp table           | 0.00001100 | 0.00000000 | 0.00000000 |                 0 |                   0 |            0 |             0 |     0 | exec                      | sql_select.cc |        1547 | | converting HEAP to MyISAM      | 3.94055900 | 3.81042100 | 0.12498100 |                 6 |                   7 |            0 |             0 |     0 | create_myisam_from_heap   | sql_select.cc |        9914 | | Copying to tmp table on disk   | 5.10490400 | 5.00623900 | 0.09798500 |                 8 |                  10 |            0 |             0 |     0 | create_myisam_from_heap   | sql_select.cc |        9968 | | Sending data                   | 3.09531800 | 2.96954900 | 0.12698100 |                 4 |                   4 |            0 |             0 |     0 | exec                      | sql_select.cc |        1925 | | converting HEAP to MyISAM      | 1.62242300 | 1.37279100 | 0.25096200 |                38 |                  15 |            0 |             0 |     0 | create_myisam_from_heap   | sql_select.cc |        9914 | | Sending data                   | 5.13815600 | 5.04223300 | 0.09698500 |                13 |                  10 |            0 |             0 |     0 | create_myisam_from_heap   | sql_select.cc |        9968 | | optimizing                     | 2.17403900 | 2.01069500 | 0.16497500 |                 5 |                   3 |            0 |             0 |     0 | optimize                  | sql_select.cc |         617 | mysql官网论坛也有讲过这配置 但没说到第二项配置 http://forums.mysql.com/read.php?22,111012,111012#msg-111012

来源: <http://www.thinksaas.cn/group/topic/124436/>

-————————————————————————————————————————————————————————————————————————————————————————————————————

http://www.mysqlab.net/knowledge/kb/detail/topic/myisam/id/6149

Discussion

The state "converting HEAP to MyISAM" happens when a query that needs a temporary table is converting from an in-memory temporary table to a disk-based temporary table.

MySQL uses memory-based temporary tables up to the size limit set by the tmp_table_size system variable. If a query needs a temporary table larger than this it will be converted to a disk-based temporary table using the MyISAM storage engine.

GROUP BY queries and ORDER BY queries that can't use an index for the ordering are the most common causes of temporary table creation.

Solution

You could consider raising the per-session value of tmp_table_size if you have sufficient memory. Use the SHOW GLOBAL STATUS statement to see the value of the Created_tmp_tables variable. It will show the total number of temporary tables that have been created:

SHOW GLOBAL STATUS LIKE 'Created_tmp_tables';

+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| Created_tmp_tables | 13    | 
+--------------------+-------+

The

Created_tmp_disk_tables

variable shows how many of those have been converted to disk temporary tables:

SHOW GLOBAL STATUS LIKE 'Created_tmp_disk_tables';

+-------------------------+-------+
| Variable_name           | Value |
+-------------------------+-------+
| Created_tmp_disk_tables | 1     | 
+-------------------------+-------+

调2个参数

tmp_table_size和max_heap_table_size ============> converting HEAP to MyISAM

来源: <http://7567567.blog.51cto.com/706378/630036>

来自为知笔记(Wiz)

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这