L
L
lexstile2019-07-11 14:26:07
MySQL
lexstile, 2019-07-11 14:26:07

Database search optimization?

There is a table with words and phrases.
There is a need to search for such words either by the first letter or by the first two letters (they are entered by the user).
Question: leave everything as it is and use the LIKE operator or add one/two more fields to the table and forcibly (go through the entire table once) enter 1-2 first letters of the word/phrase into it and search for the newly created fields without using the LIKE operator ?
Perhaps there are suggestions and others, ready to listen.
The emphasis, of course, is on performance.
Thanks in advance for the replies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
V Sh., 2019-07-11
@lexstile

Depends on the number of records in the table. In any case, your version will work faster than LIKE: make two columns (one letter and two letters), write numeric values ​​​​in them (translate letters, for example, into character codes), make two indexes on these columns and when building query in the condition also use numbers (search by numbers is faster than by characters).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question