简体   繁体   English

将InnoDB表与MyISAM表连接起来

[英]Joining InnoDB tables with MyISAM tables

We have a set of tables which contain the meta level data like organizations, organization users, organization departments etc. All these table are going to be read heavy with very few write operations. 我们有一组表,其中包含元级别数据,如组织,组织用户,组织部门等。所有这些表都将被阅读,只需很少的写操作。 Also, the table sizes would be quite small (maximum number of records would be around 30K - 40K) 此外,表格大小非常小(最大记录数量约为30K - 40K)

Another set of table store OLTP data like bill transactions, user actions etc which are going to be both read and write heavy. 另一组表存储OLTP数据,如账单交易,用户操作等,这些数据将同时读写。 These tables would be quite huge (around 30 Million records per table) 这些表格非常庞大(每张表约3000万条记录)

For the first set of tables we are planning to go with MyISAM and for the second ones with InnoDb engine. 对于第一组表,我们计划使用MyISAM,第二组使用InnoDb引擎。 Many of our features would also require JOINS on tables from these 2 sets. 我们的许多功能还需要来自这两组的桌子上的JOINS。

Are there any performance issues in joining MyISAM tables with InnoDB tables? 使用InnoDB表加入MyISAM表时是否存在任何性能问题? Also, are there any other possible issues (db backups, tuning etc) we might run into with this kind of design? 此外,还有任何其他可能的问题(数据库备份,调整等),我们可能会遇到这种设计?

Any feedback would be greatly appreciated. 任何反馈将不胜感激。

What jumps out immediately at me is MyISAM . 立即向我跳出的是MyISAM

ASPECT #1 : The JOIN itself ASPECT#1:JOIN本身

Whenever there are joins involving MyISAM and InnoDB, InnoDB tables will end up having table-level lock behavior instead of row-level locking because of MyISAM's involvement in the query and MVCC cannot be applied to the MyISAM data. 每当存在涉及MyISAM和InnoDB的连接时,InnoDB表将最终具有表级锁定行为而不是行级锁定,因为MyISAM参与查询并且MVCC不能应用于MyISAM数据。 MVCC cannot even be applied to InnoDB in some instances. 在某些情况下, MVCC甚至不能应用于InnoDB。

ASPECT #2 : MyISAM's Involvement ASPECT#2:MyISAM的参与

From another perspective, if any MyISAM tables are being updated via INSERTs, UPDATEs, or DELETEs, the MyISAM tables involved in a JOIN query would be locked from other DB Connections and the JOIN query has to wait until the MyISAM tables can be read. 从另一个角度来看,如果通过INSERT,UPDATE或DELETE更新任何MyISAM表,JOIN查询中涉及的MyISAM表将从其他数据库连接中锁定,并且JOIN查询必须等到可以读取MyISAM表。 Unfortunately, if there is a mix of InnoDB and MyISAM in the JOIN query, the InnoDB tables would have to experience an intermittent lock like its MyISAM partners in the JOIN query because of being held up from writing. 不幸的是,如果在JOIN查询中混合使用InnoDB和MyISAM,InnoDB表将不得不像JOIN查询中的MyISAM合作伙伴一样经历间歇性锁定,因为它被写入了。

Keep in mind that MVCC will still permit READ-UNCOMMITTED and REPEATABLE-READ transactions to work just fine and let certain views of data be available for other transactions. 请记住, MVCC仍然允许READ-UNCOMMITTED和REPEATABLE-READ事务正常工作,并允许某些数据视图可用于其他事务。 I cannot say the same for READ-COMMITTED and SERIALIZABLE . 我不能对READ-COMMITTED和SERIALIZABLE说同样的话

ASPECT #3 : Query Optimizer ASPECT#3:查询优化器

MySQL relies on index cardinality to determine an optimized EXPLAIN plan. MySQL依靠索引基数来确定优化的EXPLAIN计划。 Index cardinality is stable in MyISAM tables until a lot of INSERTs, UPDATEs, and DELETEs happen to the table, by which you could periodically run OPTIMIZE TABLE against the MyISAM tables. 索引基数在MyISAM表中是稳定的,直到表中发生了很多INSERT,UPDATE和DELETE,您可以定期对MyISAM表运行OPTIMIZE TABLE InnoDB index cardinality is NEVER STABLE !!! InnoDB索引基数绝对不稳定! If you run SHOW INDEXES FROM *innodbtable*; 如果你运行SHOW INDEXES FROM *innodbtable*; , you will see the index cardinality change each time you run that command. ,每次运行该命令时,您都会看到索引基数发生变化。 That's because InnoDB will do dives into the index to estimate the cardinality. 那是因为InnoDB会潜入索引来估计基数。 Even if you run OPTIMIZE TABLE against an InnoDB table, that will only defragment the table. 即使您针对InnoDB表运行OPTIMIZE TABLE ,也只会对表进行碎片整理。 OPTIMIZE TABLE will run ANALYZE TABLE internally to generate index statistics against the table. OPTIMIZE TABLE将在内部运行ANALYZE TABLE以生成针对表的索引统计信息。 That works for MyISAM. 这适用于MyISAM。 InnoDB ignores it. InnoDB忽略了它。

My advice for you is to go all out and convert everything to InnoDB and optimize your settings accordingly. 我的建议是全力以赴,将所有内容转换为InnoDB并相应地优化您的设置。

UPDATE 2012-12-18 15:56 EDT 更新2012-12-18 15:56美国东部时间

Believe it or not, there is still an open ticket on InnoDB/MyISAM joining during a SELECT FOR UPDATE . 不管你信不信, InnoDB / MyISAM在SELECT FOR UPDATE期间仍然有一张开放票 If you read it, it sums up the resolution as follows : DON'T DO IT !!! 如果您阅读它,它总结分辨率如下: 不要做它! .

我认为事务管理不会正常工作或根本不工作,因为MyISAM表不能处理它。

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

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