Fulltext Indexing on MyISAM, single column vs multiple column indexing

馋奶兔 提交于 2019-12-02 18:48:19

问题


I have an extremely large table (4M+ rows) with disk space of more than 40Gb (14Gb data and 28Gb index). I needed fulltext search on multiple fields both combined and separated, meaning that I needed to make it possible to fulltext search on both single columns and multiple columns together, like below:

for combined search

SELECT `column_a`, `column_b` FROM `table_1` WHERE MATCH (`column_a`, `column_c`, `column_x`) AGAINST ('+$search_quesry*' IN BOOLEAN MODE);

for separate search

SELECT `column_a`, `column_b` FROM `table_1` WHERE MATCH (`column_a`) AGAINST ('+search_query*' IN BOOLEAN MODE);
SELECT `column_a`, `column_b` FROM `table_1` WHERE MATCH (`column_c`) AGAINST ('+search_query*' IN BOOLEAN MODE);
SELECT `column_a`, `column_b` FROM `table_1` WHERE MATCH (`column_x`) AGAINST ('+search_query*' IN BOOLEAN MODE);

Here is my question. I have both following sets already defined as indexes, which cause 24Gb+ disk space. Did I do it right or one set is enough?

ALTER TABLE  `table_1` ADD FULLTEXT (`column_a`, `column_c`, `column_x`);

and/or

ALTER TABLE  `table_1` ADD FULLTEXT (`column_a`);
ALTER TABLE  `table_1` ADD FULLTEXT (`column_c`);
ALTER TABLE  `table_1` ADD FULLTEXT (`column_x`);

OR

ALTER TABLE  `table_1` ADD FULLTEXT (`column_a`);
ALTER TABLE  `table_1` ADD FULLTEXT (`column_c`, `column_x`);

This is mainly to reduced required disk space as well as better performance. Any better suggestion is more than welcome. Thanks :)

P.S. The cardinality numbers seem different for column_a when indexed combined and separated.


回答1:


For MyISAM:

FULLTEXT (`column_a`, `column_c`, `column_x`)

For InnoDB:

FULLTEXT (`column_a`, `column_c`, `column_x`),
FULLTEXT (`column_a`),
FULLTEXT (`column_c`),
FULLTEXT (`column_x`)

If you have version 5.6 or later, you should convert to InnoDB.



来源:https://stackoverflow.com/questions/35267528/fulltext-indexing-on-myisam-single-column-vs-multiple-column-indexing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!