简体   繁体   English

一起查询MyISAM和InnoDB表锁定问题

[英]MyISAM and InnoDB Table locking issue when queried together

I'm working on fixing up a messed up database. 我正在修复一个混乱的数据库。 I have several MyISAM and InnoDB tables in this DB. 我在此数据库中有几个MyISAM和InnoDB表。 I need to write a query that uses the following 3 tables: 我需要编写一个使用以下3个表的查询:

table_a => InnoDB
table_b => InnoDB
table_c => MyISAM

The query takes about a minute to run and I am worries about the issues this could create on our production site if table level locking will occur in my query. 该查询需要大约一分钟的时间来运行,如果在查询中发生表级锁定,这可能会在我们的生产站点上造成问题,我对此感到担心。 I'm not sure if it will based on the docs. 我不确定是否会基于文档。 I know that MyISAM locks tables and InnoDB locks rows, but I am using them together. 我知道MyISAM锁定表,而InnoDB锁定行,但是我一起使用它们。 Here is the query: 这是查询:

INSERT INTO 
    table_a (`x`, `y`, `z`)
SELECT 
    table_b.x, table_b.y, table_c.z 
FROM 
    table_b, table_c 
WHERE 
    table_b.id = table_c.id AND
    table_b.value IS NOT NULL AND
    table_b.id NOT IN (SELECT table_a.id FROM table_a WHERE 1);

I'm not sure what will happen here when this query is executed. 我不确定执行此查询时会在这里发生什么。 I think that table locking will not happen because the write occurs on table_a which is InnoDB. 我认为表锁定不会发生,因为写入发生在InnoDB的table_a上。 However I'm not sure how this will be managed because that write operation is based on reads that occur on both MyISAM and InnoDB. 但是我不确定如何管理它,因为该写操作基于MyISAM和InnoDB上发生的读取。 I'm not yet very knowledgeable on how locking is managed and I need to find out if any of these tables will lock while this query executes. 我还不太了解如何管理锁定,因此我需要找出在执行查询时这些表中的任何一个是否会锁定。 Thank you to anyone that helps. 谢谢任何有帮助的人。

The whole table_c (MyISAM) will be locked in "read mode" during the course of your query. 在查询过程中,整个table_c (MyISAM)将被锁定为“读取模式”。 This means that concurrent reads on this table will be possible, but concurrent writes will be held. 这意味着可以对该表进行并发读取,但是将保留并发写入。

If a single write is put on hold, then all subsequent reads will also be put on hold (unless they are issued in HIGH_PRIORITY ). 如果单个写入被搁置,那么所有后续读取也将被搁置(除非它们在HIGH_PRIORITY中发出)。

The other two InnoDB tables will exhibit a very similar behaviour, but possibly not on the full tables. 其他两个InnoDB表将表现出非常相似的行为,但可能不会出现在完整表上。 Only "some" rows will be locked if a suitable index can be used to honor the match clauses and the JOIN conditions (it is still possible that the whole tables become locked if table scans are required -- if no suitable index can be used, that is). 如果可以使用合适的索引来满足match子句和JOIN条件,那么只有“一些”行将被锁定(如果需要进行表扫描,则整个表仍然可能被锁定-如果无法使用合适的索引,那是)。

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

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