使用 myisam 从/幽灵表在 innodb 中进行全文搜索
我需要对两个不同表中的两个不同列进行全文索引。
唯一的问题是我使用的是 innodb,我无法进行全文索引。
我知道有诸如 sphinx 之类的选项,并且我查看了这些选项,但我觉得这是一种矫枉过正,因为要全文索引的列是 varchar(20)。
而且,“最多”可能只有大约 1,000,000 行,
我认为一个简单的选择是仅使用主键和要使用 myisam 进行索引的 varchar 来复制两个表。
有什么建议吗?有什么方法可以轻松实现这一点吗?
I need to do full text indexing for two different colums in two different tables.
The only problem is that I'm using innodb and there is no way for me to do full text indexing.
I know that there are options such as sphinx and I took a look at the options, but I feel like it's a overkill because the colums to be full-text indexed are varchar(20).
And, probably, there will be only around 1,000,000 rows "at most"
One simple option I'm thinkin is to duplicate the two tables only with the primary key and the varchar to be indexed using myisam.
any suggestion? is there any way to achieve this easily?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的方法看起来是正确的。
创建一个仅包含感兴趣字段(感兴趣的 pkey 和 varchar)的新表,引擎 myisam。
根据需要在此新表上创建全文索引。
主要的变化是使这个新表与主表保持同步。最好的方法是使用 触发器主表的插入、更新和删除。
另一个变化是防止最终用户篡改全文索引表。这也可以通过触发器来完成,但有更好的方法:创建一个数据库用户(例如 tg_user),并授予他对此表的所有权。然后撤销除select之外的所有其他用户。并确保在创建上述触发器时使用
definer
子句。Your approach seems correct.
create a new table with only the fields of interest (the pkey(s) and the varchar(s) of interest), engine myisam.
create a full text index as needed on this new table.
The main twist is to keep this new table in sync with the master table. The best means to do so is to use triggers on insert, update and delete of the master table.
An additional twist is to prevent end-users from tampering with the full text indexed table. This can be done with triggers too, but there's a better way: create a db user (e.g. tg_user), and grant him ownership of this table. Then revoke all except select to other users. And make sure that you use the
definer
clause when creating the above-mentioned triggers.我决定采用一个简单的解决方案:
首先,将行插入到 innodb 表(主表)中。然后,紧随其后,将该行插入到 myisam 表(不是触发器)。
每隔一小时左右运行一次 cron 以确保引用完整性。
查询将如下所示:
如果从行引用不存在的主行,则删除。
如果主行不存在从行,则插入。
这不是最好的解决方案,但很简单。
I decided to go with a simple solution:
First, insert the row to the innodb table (master). Then, right after it, insert the row to the myisam table (not trigger).
Run a cron ever hour or so to ensure referential integrity.
The query would be something like this:
If a slave row refers to a master row that does not exist, delete.
If a slave row does not exist for a master row, insert.
It's not the best solution, but simple.