Concurrent inserts on MyISAM and the binary log

ecently I had an interesting surprise with concurrent inserts into a MyISAM table. The inserts were not happening concurrently with SELECT statements; they were blocking and the process list was filling up with queries in Locked status.

My first thought was that the customer had deleted from the table, which leaves “holes” in the middle of it and prevents concurrent inserts. (You can configure the server to permit concurrent inserts even when there are holes, but it’s disabled by default.) However, that turned out not to be the cause; the table was only inserted into (and selected from). Instead, the blocked statements were because of INSERT… SELECT statements that were running against the table, selecting data from it and inserting into another table.

Let’s look at what happens here: suppose you have two tables tbl1 and tbl2 and concurrent inserts into tbl2 are running fine. If you now run the following query,

INSERT INTO tbl1 SELECT * FROM tbl2

The concurrent inserts into tbl2 can block. This happens if you have the binary log enabled. If you think about it, this makes sense and is correct behavior. The statements have to be serialized for the binary log; otherwise replaying the binary log can result in a different order of execution.

The MySQL manual actually says this, but not in the clearest way. It just says

If you are using the binary log, concurrent inserts are converted to normal inserts for CREATE … SELECT or INSERT … SELECT statements.

If you use mysqladmin debug, you’ll see an ordinary SELECT gets a lock on the table like this:

Locked - read         Low priority read lock

But on INSERT…SELECT, you’ll see this:

Read lock  without concurrent inserts

That read lock is what’s blocking the concurrent inserts from happening.

There’s no solution to this, if you need the binary log enabled. (It needs to be enabled for replication.) There are workarounds, though. You can use the old trick of SELECT INTO OUTFILE followed by LOAD DATA INFILE. You can use InnoDB instead. Or you can do something more elaborate and application-specific, but that’s a topic for another post.

参考:

http://www.percona.com/blog/2008/05/14/concurrent-insert-select-myisam/

时间: 2024-10-10 02:55:22

Concurrent inserts on MyISAM and the binary log的相关文章

MySQL二进制日志(binary log)总结

本文出处:http://www.cnblogs.com/wy123/p/7182356.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错误进行修正或补充,无他) 今天无意中发现了一个云栖社区举行的MySQL“第一季:挑战玄惭之 慢SQL性能优化赛”,在测试服务器上执行其测试脚本写入数据的时候报错提示如下,Multi-statement transaction required more than 'max_binlog_cache_

关于binary log那些事

阅读目录(Content) 1 what's binary log 2 Binary Logging Options and Variables 2.1 基础参数 2.2 重要参数(sync_binlog=0丢失数据的描述有疑问,目前查阅相关资料跟咨询业界人士中....) 3 Binary Logging Formats 3.1 binlog_format=statement 3.2 binlog_format=row 3.2.1 binlog_row_image默认full,binlog_ro

关于binary log一点总结[转]

阅读目录(Content) 1 what's binary log 2 Binary Logging Options and Variables 2.1 基础参数 3 Binary Logging Formats 3.1 binlog_format=statement 3.2 binlog_format=row 3.2.1 binlog_row_image默认full,binlog_rows_query_log_events默认false 3.2.2 binlog_rows_query_log_

清除mysql binary log

作为一个oracle dba有时候不得不管理一下mysql数据库,当为主从库时需要阶段性清理mysql binary log,清楚方式如下: 首先查看mysql 的当前日志组 show master status; 确定当前日志组后删除日志文件 purge binary logs to 'mysql-bin.000795'; 删除000795之前的日志 清除mysql binary log,布布扣,bubuko.com

binary log初探

binary log是mysql中一个重要的部分,主要作用有两个: Replication:在master端开启binary log后,log会记录所有数据库的改动,然后slave端获取这个Log文件内容就可以在slave端进行同样的操作. 备份:在某个时间点a做了一次备份,然后利用binary log记录从这个时间点a后的所有数据库的改动,然后下一次还原的时候,利用时间点a的备份文件和这个binary log文件,就可以将数据还原. 与binary log相关的参数如下: log-bin和lo

MySQL 5.7 开启binary log(binlog)及注意事项

二进制日志语句Binary Log ,我们俗称binlog,记录数据库更改的数据,常用于主从复制环境和恢复 备份. 开启binlog比较简单,Centos7环境打开my.cnf配置文件,添加 server-id = [序列号] log-bin = [文件名] 5.7.3以后版本必须配置server-id,文件名可配置绝对路径,即可开启binlog. binlog配置有几个特殊点,需要注意 1,文件名如果是绝对路径,在这种情况下,索引必须是手动编辑,即在my.cnf配置文件添加 log-bin-i

Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT.

一.问题描述  014-12-15 20:00:29 4398 [Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. INSERT... ON DUPLICATE KEY UPDATE  on a table with more than one UNIQUE KEY is unsafe Statement: INSERT INTO 

mysql从库Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'报错处理

年后回来查看mysql运行状况与备份情况,登录mysql从库查看主从同步状态 1 mysql> show slave status\G; 2 *************************** 1. row *************************** 3 Slave_IO_State: 4 Master_Host: 101.200.*.* 5 Master_User: backup 6 Master_Port: 3306 7 Connect_Retry: 60 8 Master_

MySQL 二进制日志(Binary Log)

同大多数关系型数据库一样,日志文件是MySQL数据库的重要组成部分.MySQL有几种不同的日志文件,通常包括错误日志文件,二进制日志,通用日志,慢查询日志,等等.这些日志可以帮助我们定位mysqld内部发生的事件,数据库性能故障,记录数据的变更历史,用户恢复数据库等等.二进制日志,也叫binary log,是MySQL Server中最为重要的日志之一,本文主要描述二进制日志. 1.MySQL日志文件系统的组成   a.错误日志:记录启动.运行或停止mysqld时出现的问题.   b.通用日志: