简体   繁体   English

MySQL存储引擎的困境

[英]MySQL storage engine dilemma

There are two MySQL database features that I want to use in my application. 我想在我的应用程序中使用两个MySQL数据库功能。 The first is FULL-TEXT-SEARCH and TRANSACTIONS. 第一个是FULL-TEXT-SEARCH和TRANSACTIONS。

Now, the dilemma here is that I cannot get this feature in one storage engine. 现在,这里的困境是我无法在一个存储引擎中获得此功能。 It's either I use MyIsam (which has the FULL-TEXT-SEARCH feature) or I use InnoDB (which supports the TRANSACTION feature). 它要么我使用MyIsam(具有FULL-TEXT-SEARCH功能),要么使用InnoDB(支持TRANSACTION功能)。 I can't have both. 我不能兼得。

My question is, is there anyway I can have both features in my application before I am forced to make a choice between the two storage engines. 我的问题是,无论如何,在我被迫在两个存储引擎之间做出选择之前,我可以在我的应用程序中同时拥有这两个功能。

Possible workarounds: 可能的解决方法:

  1. Use Sphinx or Solr or some other external text search engine for your text searches and use InnoDB engine. 使用Sphinx或Solr或其他一些外部文本搜索引擎进行文本搜索并使用InnoDB引擎。

  2. Write your own search code - and use InnoDB. 编写自己的搜索代码 - 并使用InnoDB。 This is not really an option, unless you search needs are limited or your budget is huge. 这不是一个真正的选择,除非您的搜索需求有限或您的预算很大。

  3. Use both engines, MyISAM and InnoDB. 使用两个引擎,MyISAM和InnoDB。 Keep the columns you want to be full-text searching in MyISAM and the rest in InnoDB. 保留要在MyISAM中进行全文搜索的列,其余的在InnoDB中。 This will be risky as the data in MyISAM will not be transaction safe. 这将是有风险的,因为MyISAM中的数据不是交易安全的。

  4. Use both engines, MyISAM and InnoDB. 使用两个引擎,MyISAM和InnoDB。 Keep all data in InnoDB and duplicate the columns you want to be full-text searching in MyISAM. 将所有数据保存在InnoDB中,并复制要在MyISAM中进行全文搜索的列。 This will need some mechanism (triggers) for the data duplication. 这将需要一些机制(触发器)进行数据复制。

  5. Wait for the version of MySQL where full-text search will be supported by InnoDB or other transactional engine. 等待InnoDB或其他事务引擎支持全文搜索的MySQL版本。

  6. (Option 4) but use MariaDB (a MySQL fork) which has "crash-safe" (but still not transaction-safe) full text indexes: When-will-transactional-fulltext-indexes-be-ready? (选项4)但是使用具有“崩溃安全”(但仍然不是事务安全)全文索引的MariaDB(一个MySQL分支): 什么时候将要事务全文本索引准备好?

  7. Use other RDBMS like PostgreSQL that has full-text support in transactional engine. 使用其他RDBMS,如PostgreSQL,它在事务引擎中具有全文支持。

If you need to perform transactions and full-text against a single table in MySQL, you have a few options. 如果您需要对MySQL中的单个表执行事务和全文,您有几个选择。 But really the salient point to take away from this entire discussion is that databases are not good at doing full-text search to begin with (especially MySQL!) and ideally you want to offload this work to a component that is better at performing this type of task. 但实际上,从整个讨论中拿走的重点是数据库不擅长开始全文搜索(特别是MySQL!),理想情况下你想将这项工作卸载到一个更好地执行这种类型的组件上任务。

Option 1: 选项1:

Create one table that you need to do the transaction against as InnoDB and then create another "mirror" table that is MyISAM that you can do full-text search against. 创建一个表,您需要作为InnoDB进行事务处理,然后创建另一个MyisAM“镜像”表,您可以对其进行全文搜索。 You can keep the data in sync through the use of a trigger on the InnoDB table. 您可以通过使用InnoDB表上的触发器使数据保持同步。 Sort of a hack but it will work. 一个黑客,但它会工作。

Option 3: 选项3:

Take a look at a 3rd party full-text engine like Sphinx , Lucene or Solr . 看看像SphinxLuceneSolr这样的第三方全文引擎。 This way you can focus on designing your database to be optimal at querying data and not forcing it to do text search as well. 这样,您可以专注于将数据库设计为查询数据时的最佳状态,而不是强制它进行文本搜索。

Option 3: 选项3:

You can choose to go with a different database server that supports transactions and full-text search at the same time, such as SQL Server. 您可以选择使用同时支持事务和全文搜索的其他数据库服务器,例如SQL Server。

Hope this give you some clarity. 希望这能给你一些清晰度。

Enjoy! 请享用!

The MyISAM full-text index probably isn't as good as you think. MyISAM全文索引可能没有您想象的那么好。 It works ok(ish) on small data, but is lousy on bigger data. 它在小数据上运行正常(ish),但在更大的数据上却很糟糕。

In MySQL 5.6 we may have full-text on InnoDB, however it still does not support most of the features that a real full-text search engine would have. 在MySQL 5.6中,我们可能在InnoDB上有全文,但它仍然不支持真正的全文搜索引擎所具有的大多数功能。

there is no way to have both in the same database engine, these are the constraints given by the design how MySQL works. 没有办法让两者都在同一个数据库引擎中,这些是设计给出的MySQL如何工作的约束。 You can not change physics. 你无法改变物理。 ;-) ;-)

http://dev.mysql.com/doc/refman/5.1/en/innodb-restrictions.html http://dev.mysql.com/doc/refman/5.1/en/innodb-restrictions.html
http://dev.mysql.com/doc/refman/5.1/en/ansi-diff-transactions.html http://dev.mysql.com/doc/refman/5.1/en/ansi-diff-transactions.html

when you're still in design phase, you may also consider using another SQL implmentation for your project which supports both in the same engine. 当你还处于设计阶段时,你也可以考虑为你的项目使用另一个SQL implmentation,它支持同一个引擎。 Postgres for example does. Postgres例如。

http://wiki.postgresql.org/wiki/Why_PostgreSQL_Instead_of_MySQL_2009#Transactions_and_the_Database_Engine_Core http://wiki.postgresql.org/wiki/Why_PostgreSQL_Instead_of_MySQL_2009#Transactions_and_the_Database_Engine_Core

One another option is to use MySQL's support for replication: 另一种选择是使用MySQL对复制的支持:

For example you can setup master server with InnoDB storage engine. 例如,您可以使用InnoDB存储引擎设置主服务器。 Then replicate to another read-only server with the MyISAM storage engine. 然后使用MyISAM存储引擎复制到另一个只读服务器。

You can use almost any MySQL storage engine and there might be some that support better search features than MyISAM for some use cases. 您可以使用几乎任何MySQL存储引擎,并且可能有一些支持比MyISAM更好的搜索功能用于某些用例。

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

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