H
H
HellWalk2017-08-11 11:41:19
MySQL
HellWalk, 2017-08-11 11:41:19

What is the best way to optimize the %name% query?

Hello
At work I delve into a new project, I solve the accumulated bugs. Solving one of them, I saw this part of the request:

`post`.`tags` LIKE 'пресс-релиз,%' OR
`post`.`tags` LIKE '%, пресс-релиз,%' OR
`post`.`tags` LIKE '%,пресс-релиз' OR
`post`.`tags` LIKE 'пресс-релиз'

Not only is such a query incorrect - for example, it does not find the string "Bulgaria, statistics, press release", the question arises - is it not better to simply write:
`post`.`tags` LIKE '%пресс-релиз%'
?
PS Under the "press release", of course, any word (tag) is meant.
PPS I measured the execution of requests in phpMyAdmin, the second one is executed twice as fast, but the numbers jump very much there, I don’t know how correct it is to replace the query execution speed in this way.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2017-08-11
@Rsa97

If this is a string of tags, then it is best to remake the database - move the tags to a separate table and add an additional link table.

I
imhuman, 2017-08-11
@imhuman

Here, apparently, there was an attempt to exclude results from the sample with the occurrence of a part of the word, for example, LIKE '%лес%'will find колесо, but somehow crooked and pointless. Can be used REGEXPin your case, but it's not the fastest query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question