benphp Posted June 7, 2008 Share Posted June 7, 2008 I have a search query that searches longtext for search terms, and the queries are starting to bog down. Would it help to index a text field that can contain 5000 chars or more? Thanks! Quote Link to comment Share on other sites More sharing options...
benphp Posted June 7, 2008 Author Share Posted June 7, 2008 While I was waiting, I did some testing. OMYGOD what have I been missing? For anyone who hasn't done this, index your long text tables so: ALTER TABLE `tablename` ADD FULLTEXT (textfield1); ALTER TABLE `tablename` ADD FULLTEXT (textfield2); then change your select statements from WHERE textfield1 LIKE '%$term%' to WHERE MATCH (textfield1) AGAINST ('$term') What a difference! Quote Link to comment Share on other sites More sharing options...
benphp Posted June 7, 2008 Author Share Posted June 7, 2008 Okay, so can someone tell me why it's not a good idea to index everything? Quote Link to comment Share on other sites More sharing options...
fenway Posted June 10, 2008 Share Posted June 10, 2008 Okay, so can someone tell me why it's not a good idea to index everything? Because not every query can utilize every index (very true for 4.1) and it's expensive to keep it up to date. Quote Link to comment Share on other sites More sharing options...
benphp Posted June 13, 2008 Author Share Posted June 13, 2008 Expensive in storage or time? If I understand correctly, it takes a little more time to enter a new record if a table is indexed, and the index itself takes disk space. Is that what you mean by expensive? Quote Link to comment Share on other sites More sharing options...
fenway Posted June 14, 2008 Share Posted June 14, 2008 Both, but time is more important -- unless the table really grows, and then index performance drops with increasing size. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.