`
kingmove
  • 浏览: 5451 次
  • 性别: Icon_minigender_1
  • 来自: 肇庆
社区版块
存档分类
最新评论

Copying to tmp table[转]

阅读更多

Copying to tmp table
January 26th, 2009

MySQL may use temporary tables during query execution. Ideally you would want to avoid this, since its an expensive and slow operation. It can be avoided by optimizing queries. Sometimes it can’t be completely avoided – in that case you want to make sure the temporary table is created as a “memory” storage engine table, since its very fast, as it is never written to disk and remains, as the name states, in memory. But, as the manual explains, there are some conditions, such as TEXT/BLOB columns, or a combination of GROUP BY/ORDER BY clauses that makes MySQL write the temporary table to disk as a MyISAM table. One can spot these queries by the EXPLAIN output:
[...] Using where; Using temporary; Using filesort
In that case performance depends on disk I/O speed. If there are multiple similar queries running simultaneously, they try to read/write a lot of information to the disk, and will become extremely slow.

Solution? TMPFS!

tmpfs is a filesystem, that resides in RAM/Swap, so if your server has enough available RAM, files written there will bypass disk I/O completely, and will perform significantly faster.

Now, “High Performance MySQL, Second Edition” claims that this solution is still not as good as a MEMORY table, since it requires MySQL to use some expensive OS calls to write & read the temporary table, but it is still faster than the disk based temporary table.

To set it up, just mount a tmpfs system on an empty directory (you should also add this to fstab):
mount tmpfs /tmpfs -t tmpfs
and edit my.cnf to make MySQL use that directory as a temporary directory:
tmpdir = /tmpfs
Be careful though, there is a bug in some versions that prevents this from working properly.

For more information, see this blog.

分享到:
评论

相关推荐

    MySQL性能分析show profiles详解(csdn)————程序.pdf

    8. **Copying to tmp table on disk**:内存中的临时表被复制到磁盘,这是一个性能警告。优化索引,考虑增加`tmp_table_size`以扩大内存临时表的大小。 在实际工作中,针对不同的性能问题,我们需要结合`SHOW ...

    MySQL通过show processlist命令检视性能的讲解

    理解这些状态有助于我们识别潜在的问题,比如长时间的`Copying to tmp table on disk`可能意味着需要优化查询以减少临时表的使用,或者增大`tmp_table_size`配置。同样,`Locked`状态可能指示存在死锁或锁竞争。 总...

    通过mysql show processlist 命令检查mysql锁的方法

    例如,如果看到大量线程处于`Copying to tmp table on disk`状态,可能意味着需要调整`tmp_table_size`参数,避免频繁将临时表写入磁盘,从而提升性能。 通过观察`SHOW PROCESSLIST`输出,可以发现慢查询、锁定问题...

    查找MySQL中查询慢的SQL语句方法

    MySQL列出的状态有很多,例如`Checking table`表示正在检查数据表,`Closing tables`表示正在刷新数据并关闭表,`Copying to tmp table on disk`表示由于临时结果过大,正在将数据写入磁盘。`Creating tmp table`、`...

    mysql show processlist 显示mysql查询进程

    例如,如果你发现很多线程都处于`Copying to tmp table on disk`状态,可能意味着查询需要优化,以减少对内存或磁盘资源的需求。 `mysqladmin processlist`命令与`SHOW PROCESSLIST`类似,但它是通过mysqladmin工具...

    MySQL使用profile查询性能的操作教程

    1. **避免全表扫描**:如果`Sending data`或`Copying to tmp table`阶段时间较长,可能是因为查询没有有效的索引或者索引使用不当,导致大量数据需要读取或临时表创建。 2. **减少锁等待**:如果`Waiting for query ...

    processlist命令 查看mysql 线程

    - `State`列中的各种状态可以帮助识别潜在的问题,比如长时间的`Waiting for table metadata lock`可能表明有锁定问题,`Copying to tmp table on disk`可能表示内存不足,导致数据需写入磁盘临时表。 5. **优化和...

    DB Query Analyzer》中断SQL语句的执行

    - 对于MySQL数据库,可以观察到与《DB Query Analyzer》相关的进程状态从“Copying to tmp table”变为其他状态,表明SQL语句的执行已成功中断。 #### 加壳技术带来的误报问题 值得注意的是,《DB Query Analyzer...

    apktool documentation

    original = META-INF folder / AndroidManifest.xml, which are needed to retain the signature of apks to prevent needing to resign. Used with -c / --copy-original on [b]uild unknown = Files / folders ...

    Mysql占用过高CPU时的优化手段(必看)

    8. **调整临时表大小**:如果看到很多"Copying to tmp table on disk"状态,可能是临时表太大导致的,可以增大`tmp_table_size`以减少磁盘I/O,提高性能。 9. **限制最大连接数**:通过调整`max_connections`限制...

    Mysql-使用show profiles分析你的SQL

    “Copying to tmp table on disk”是内存中临时表无法容纳数据,转而存储到磁盘上,这会严重影响性能;而“locked”状态则可能表示出现了死锁。遇到这些情况时,通常需要重构查询、优化索引或者调整数据结构以提高...

    percona-toolkit之pt-kill 杀掉mysql查询或连接的方法

    - `--ignore-*` 和 `--match-*` 参数:可以用于忽略或匹配特定的命令(如`Query`、`Sleep`等)、数据库、主机、信息(如`select`、`update`等)或状态(如`Locked`、`Copying to tmp table`等)。 通过灵活使用这些...

    MySQL调优利器【show profiles】

    这样,你可以得到每个状态(如`Sending data`、`Copying to tmp table`等)的持续时间、CPU用户时间、CPU系统时间、块I/O读写时间等相关指标,这些数据对于识别性能瓶颈和优化SQL语句极其有用。 在实际的数据库性能...

    mysql慢查询操作实例分析【开启、测试、确认等】

    找出那些状态为`Sending data`或`Copying to tmp table`等占用资源较多的查询。 ```sql SHOW FULL PROCESSLIST; ``` - **分析`EXPLAIN`结果**:在执行查询前,先使用`EXPLAIN`关键字来预览查询计划,这可以帮助...

    MySQL数据库show processlist指令使用解析

    7. State:这个字段显示使用当前连接的SQL语句的状态,它描述了SQL语句执行过程中的一个具体阶段,例如正在复制到临时表(copying to tmp table)、正在排序结果(sorting result)、正在发送数据(sending data)等...

    使用pt-kill根据一定的规则来kill连接的方法

    pt-kill --match-command Query --match-state "Copying to tmp table" --busy-time 5 --host <hostname> --port <interval> --interval <interval> --print --kill --victims all ``` 在使用`pt-kill`时,务必...

    linux全志R16的linux系统编译的资料_20170502_1655.7z

    全志R16平台编译linux系统V1.0.txt 2017/4/11 13:36 (编译请使用编译android的lichee的选项编译生成的.config文件,不然直接编译会报错!!...rootroot@cm-System-Product-Name:/home/...Preparing to unpack ......

Global site tag (gtag.js) - Google Analytics