Forum Moderators: open
i want my search engine to find all the records matching a criteria on at least one of them .
my question is, wouldn't it be faster to replace those two fields with one varchar(200) field, use a delimiter between their values (e.g:"title value@@@sub-title value"),
so that when i run queries on this table it will only take one query ("select * from table where TitleAndSubtitle like '%texttofind%'") rather than having two fields and thus two queries, one query for each field..
so, what's faster ?
you should of course only select the fields you want returned (and not *) because this cuts down on passing data between the mysql server and your application to what is needed... this does of course save bandwidth and possibly time.
you should set a full text index on each of the varchar columns you want to search in - this will speed things up considerably.
regarding wether you should 'merge' the 2 columns, technically you would have to do 2 passes to search 2 fields, which is longer, but the single field would take longer to search, so only testign would give the answer in your case.
setting the full text index on both fields (or the single field if you merge them) will make a significant difference.
as these are different!
%text_to_search% is looking for an exact phrase match somewhere in the filed
to search for the words in any order you would need to do something like:
LIKE %text% AND LIKE %to% AND LIKE %search%
so is it better to convert everything to a unified lower/upper case letters, so that mysql will have a better chance of finding a certain expression faster ?
and if it does make the queries run faster, is it negligible or does it have a major performance improvement?
if you are looking for minor tweaks then you need to ask questions like:
am i doing updates and inserts or just look-ups? depending on the proportion of the two then different types of table work better.
i would suggest you import your database onto your local machine, and use mysql query browser to test different indexes or whatever, you can run queries and it tells you how long they took ... try it with different indexes.
[it is not a perfect way to test but it is a good way]
with databases there is rarely a definative/universal fastest way, it can be very specific to your circumstances.
remember too that there is likely a network bottleneck between the mysql server and the webserver, which will slow your application down anyway (especially in a shared hosting environment)