I'm developing my own CMS and using MySql v5.5 DB to save the content items records.
Due to a technical limitations, I can't upgrade my database to a newer version that support Full-Text searches on InnoDB tables.
Would it be a good practise to use MyISAM tables for textual searches while the "real" data is saved in InnoDB storage engine?
Example:
- The user create content item and save it to the database
- All the content item fields are saved to an InnoDB table.
- All textual fields are STACKED together and saved in a single field inside a MyISAM table which also include additional ID field with reference to the original content item.
When the user perform a textual based search, I'll query against the MyISAM table using a Full-Text search query which will give me references to all the matching records in my InnoDB table.
The bottom line – Is that considered to be a good solution performance-wise and for improving the searching capabilities of my CMS, or should I stick with the good old LIKE operator and query using only the InnoDB table?
Best Answer
It works. It performs reasonably well.
You have two tables, one is InnoDB and contains most of the attributes of an entity. The other is MyISAM, is 1:1 with the first table, and contains a
TEXT
field, plusFULLTEXT
index.The relevant query looks something like:
I think that the
MATCH
will always occur first, even though the tests oni
might be more selective. That is the nature ofFULLTEXT
.jkavalik mentioned some consistency issues; but these can mostly be avoided by carefully picking the order in which you
INSERT
into the two tables, and whether you useREPLACE
orIODKU
instead of a plainINSERT
for one of the `INSERTs.(I believe I have done what you describe in one or two projects. I have since measured that InnoDB's
FULLTEXT
seems to be faster.)Bottom line: Go ahead and do it.
Addendum How to order the statements to minimize data integrity problems.
Cases...
INSERTs
succeed or both fail.INSERT
, you should catch it andROLLBACK
instead ofCOMMIT
. Hence good integrity.COMMIT
fails, there will be an extra row in the MyISAM Table, for which there is no InnoDB row. Two cases...If a
FULLTEXT
search hits that row, then theJOIN
to the InnoDB table will fail, thereby getting the 'right' answer (at a minor cost).If you come along later and reuse that
id
to re-insert the row (or insert a different row), then the IODKU will "do the right thing". All is well.Note (aimed at other readers): This technique of mixing an InnoDB table with a non-transactional
INSERT
works in other cases. Consider putting an image (.jpg) in a file, while putting the image's 'meta data' in an InnoDB row. At worst, you might have an extra or duplicate image stored in the file system.