Three tables, Media (Media), Tags (tag), MediaTagRef table (middle)
Three tables number respectively is: Media, 5 w, Tags, 5 w, 80 w MediaTagRef
Now you need to do keyword filtering search for Media, Media. The name LIKE '% 1%' OR Tags LIKE
'% 1%'
SELECT
Count (*)
The FROM
(
SELECT
Media. Id, Media. The name
The FROM
Mc_media Media
LEFT the JOIN Mc_media_tag_ref TagRef ON TagRef. Object_id=Media. Id
LEFT the JOIN Mc_tags Tags ON Tags. Id=TagRef. Tag_id
WHERE Tags. The name LIKE '% 1%' OR Media. The name LIKE '% 1%'
20 # LIMIT
C)
Results: 651455
The affected line: 0
Time: 7.113 s
Returns the result need more than 7 seconds, it's can not accept, is there to write wrong?
Even if like to also want to 7 seconds,
CodePudding user response:
SELECT
Media. The id of the
Media. The NAME
The FROM
Mc_media Media
LEFT the JOIN Mc_media_tag_ref TagRef ON TagRef. Object_id=Media. Id
LEFT the JOIN Mc_tags Tags ON Tags. Id=TagRef. Tag_id
WHERE
Tags. The NAME LIKE '% 1%'
The OR Media. The NAME LIKE '% 1%'
LIMIT of 20
This query within 100 ms, but unable to know the total number, can't do paging,
Also please help to see see!!
CodePudding user response:
From the point of the where condition, both like % 1%, fully using the index of less than, poor performance will of course, also need to see how filterability indexes, the filterability again within 10% agree that can effectively use the index.CodePudding user response: