简体   繁体   English

论坛帖子表应该使用MyISAM还是InnoDB

[英]Should a forum posts table use MyISAM or InnoDB

For a forum, should I use MyISAM or InnoDB for the table that stores the text? 对于论坛,我应该对存储文本的表使用MyISAM还是InnoDB?

I know that MyISAM supports full text searching , which sounds like it's what I should go for, but while reading, I've come across this very confusing sentence. 我知道MyISAM支持全文搜索 ,这听起来像是我应该追求的,但是在阅读时,我遇到了这个非常令人困惑的句子。

You should use InnoDB when transactions are important, such as for situations in which INSERTs and SELECTs are being interleaved, such as online message boards or forums. 当事务很重要时,例如在插入INSERT和SELECT的情况下,例如在线留言板或论坛,您应该使用InnoDB。

Well, but for an "online message boards or forums" I would need good search to search through the text of each post, so doesn't it make more sense to use MyISAM? 好吧,但是对于“在线留言板或论坛”,我需要很好的搜索才能搜索每个帖子的文本,因此使用MyISAM更加有意义吗? Can someone clarify what's most commonly used? 有人可以弄清楚最常用的是什么吗?

Apart from MySQL's native full text searching solution, which as you already identified requires the MyISAM storage engine, you may also want to consider the popular third-party search engines Sphinx and Apache Lucene , with which you can use InnoDB tables. 除了MySQL的本机全文搜索解决方案(您已经确定需要MyISAM存储引擎)之外,您可能还需要考虑流行的第三方搜索引擎SphinxApache Lucene ,您可以使用它们使用InnoDB表。

You could also stick to MySQL's solution, and use InnoDB storage for all tables except for one table which will simply hold the post_id and text_body . 您还可以坚持使用MySQL的解决方案,并对所有表使用InnoDB存储,但其中一个表仅包含post_idtext_body This is assuming that you only require full text searching for the content of forum posts. 这是假设您只需要全文搜索论坛帖子的内容。

In addition note that while the major deficiency of MyISAM is the lack of transaction support, there are other important issues as well for a production system. 另外请注意,虽然MyISAM的主要缺陷是缺乏交易支持,但生产系统还存在其他重要问题。 You may want to check the following article for further reading: 您可能需要检查以下文章以进一步阅读:

For any large volume of text I'd use InnoDB to store it and Sphinx to index it. 对于大量文本,我将使用InnoDB进行存储,并使用Sphinx对其进行索引。 It provides a lot more search features than what's built into mysql. 它提供了比mysql内置的功能更多的搜索功能。

Generally speaking, for non-critical data, I'd use InnoDB tuned for speed. 一般来说,对于非关键数据,我将使用为速度而调整的InnoDB。 (Eg, I wouldn't flush binary logs on every commit.) I'd only use MyISAM for things like logging tables. (例如,我不会在每次提交时刷新二进制日志。)我只会将MyISAM用于日志表之类的事情。

As others have mentioned, you can use external search indexes if you need to do full text searches. 正如其他人提到的,如果需要全文搜索,则可以使用外部搜索索引。 They are more powerful and faster than MySQL's. 它们比MySQL的功能强大且速度更快。

Regarding the part about transactions, it's a bit of a lie. 关于交易部分,这是一个谎言。 You could do the same thing with MyISAM by locking tables for WRITE. 通过锁定WRITE表,您可以对MyISAM做同样的事情。 If you are inserting into, say, three tables when posting a message, you could lock all three tables for WRITE, and the data would look consistent (assuming all three INSERTS succeeded). 如果要在发布消息时插入三个表,则可以锁定所有三个表以进行WRITE,并且数据看起来将是一致的(假设所有三个INSERTS成功)。

But the problem with that is you are locking the entire table, which can slow down concurrent usage. 但是,这样做的问题是您锁定了整个表,这可能会降低并发使用率。 In fact, that is one of InnoDB's major advantages over MyISAM: it has row-level locking. 实际上,这是InnoDB与MyISAM相比的主要优点之一:它具有行级锁定。

In short: if you are unable to set up an external indexer, and your site does not experience too much traffic, then MyISAM will work fine despite it being less robust. 简而言之:如果您无法设置外部索引器,并且您的站点没有太多的流量,则MyISAM可以正常运行,尽管它的健壮性较低。 You can emulate the consistency of transactions with table locks. 您可以使用表锁模拟事务的一致性。 (I do not mean to make it sound like the table locking is somehow equivalent to transactions.) (我并不是说听起来像表锁定在某种程度上等同于事务。)

Otherwise, I'd use InnoDB with an external indexing service. 否则,我将InnoDB与外部索引服务一起使用。

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

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