简体   繁体   English

插入..Select到InnoDB表中,每次插入后都提交?

[英]Insert..Select into InnoDB table with commit after each insert?

I just finished creating a new partitioned table to replace an old, non-partitioned table (renamed for safekeeping). 我刚刚完成创建新的分区表,以替换旧的,未分区的表(为安全起见而重命名)。 I copied the newest data from the old table into the new table at the time I created it, but I still have roughly half the data left to copy over. 在创建数据时,我已将旧表中的最新数据复制到新表中,但仍有大约一半的数据需要复制。 The problem is, it's a live web service getting hammered nonstop, and every time I try to copy a chunk over via INSERT..SELECT, it insists on doing it as an atomic transaction (which consumes all the server's resources, slows everything to a crawl, and probably pushes the server dangerously close to running out of physical resources). 问题是,这是一个实时的Web服务,会不断受到冲击,每次我尝试通过INSERT..SELECT复制块时,它都坚持将其作为原子事务进行(这消耗了服务器的所有资源,将所有内容减慢到爬网,并可能使服务器危险地接近耗尽物理资源)。

Just to be clear: OldTable is MyISAM. 只需清楚一点:OldTable是MyISAM。 NewTable is InnoDB and partitioned by range on its primary key 'a'. NewTable是InnoDB,按其主键“ a”上的范围进行分区。 Both tables have identical field names. 两个表具有相同的字段名称。 The fields themselves aren't identical, but where they differ, the fields in NewTable are bigger. 字段本身并不相同,但是在不同之处,NewTable中的字段更大。

The query that's causing problems looks like: 引起问题的查询如下所示:

INSERT INTO NewTable (a,b,c,d,e,f,g) 
SELECT a,b,c,d,e,f,g 
FROM OldTable 
WHERE a > 300000000 AND a <= 400000000
order by a

What I'd like for it to do: either commit after each insert, or just dispense with transactional integrity entirely and allow dirty reads to happen if they happen. 我想要它做的是:在每次插入后提交,或者完全放弃事务完整性,如果发生脏读,则允许它们发生。

Locking NewTable (beyond possibly the one single row being inserted) is unacceptable. 锁定NewTable(可能超出插入的单个行)是不可接受的。 Locking OldTable is fine, because nothing else is using it anymore, anyway (besides the SQL to copy it to the new table, of course). 锁定OldTable很好,因为无论如何,别的东西都不再使用它了(当然,除了将SQL复制到新表之外,SQL也是如此)。

Also, is there a way to tell MySQL to do it at the lowest possible priority, and only work on the task in its (relative) free time? 另外,是否有一种方法可以告诉MySQL以最低的优先级执行操作,并且仅在其(相对)空闲时间内完成任务?

In addition to reducing the number of rows being inserted at a time, try increasing the value of bulk_insert_buffer_size system variable to something more appropriate for your case? 除了减少一次插入的行数之外,还尝试将bulk_insert_buffer_size系统变量的值bulk_insert_buffer_size更适合您的情况? The default value is 8MB. 默认值为8MB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM