I have a table (about 5 columns), which is loaded once and never updated. One of its columns is string (titles up to 100 chars). The content of this column will be searched as the whole value (select * from books where title = ‘Effective C++’ or as a single word (select * from books where title like ‘%C++%’;). The table contains millions raws. Selects are done mostly on this string column.
What is the effective design?
Is creating index for my string column is sufficient? I am doing LOAD DATA LOCAL INFILE. What is faster to create an index while creating a table or first load data without index an only than create an index?
Do I need index for all 100 chars, if most of the time I have no more than 30-40 chars?
Maybe I need FULLTEXT index?
You should load the data in table with Index it is faster in MySQL as separate index creation does full table rebuild. Plus for MyISAM table LOAD DATA INFILE automatically does index build once your data is loaded.
Now regarding indexing - index on title will help “=” queries and prefix like queries, such as like “C++%” but it will not help LIKE “%word%” Queries.
For such queries using full text search should be good idea.
Speaking about indexing - I would start with indexing full titles - if title is 30 chars long index entry will also only take about 30 chars, or even less for MyISAM tables as key compression is used.
Understood. Thank you.
BTW, when I load my db using LOAD DATA LOCAL INFILE command from number of files one after another,does it still worth to define index in initial table definition or it’s better to load all the files without index and only then apply an index?