So, essentially, I have two tables containing URLS and TAGS, with a has-and-belongs-to-many relationship between them through TAGS_URLS join tables.
A simple query to search for URLs by tags would look like this:
SELECT urls.id FROM urls
INNER JOIN tags_urls ON urls.id=tags_urls.url_id
INNER JOIN tags ON tags_urls.tag_id=tags.id
WHERE tags.tag IN ("sample","tag","list");
However, I am trying to recover the intersection of the entire URL containing the entire set of tags. Ie, only the URL containing the tag "sample" AND "tag" AND "list".
I have a working request, but I cannot complete the request in less than 30 seconds.
SELECT a.id
FROM
(SELECT DISTINCT urls.id FROM urls
INNER JOIN tags_urls ON tags_urls.url_id=urls.id INNER JOIN tags ON tags.id=tags_urls.tag_id
WHERE tags.tag = 'sample') a
JOIN
(SELECT DISTINCT urls.id FROM urls
INNER JOIN tags_urls ON tags_urls.url_id=urls.id INNER JOIN tags ON tags.id=tags_urls.tag_id
WHERE tags.tag = 'list') b
ON a.id = b.id;
The result set is correct, but the performance is terrifying.
Redis URL-, , - .
SINTER "tag-sample" "tag-list"
MySQL Redis SINTER?