Multiple Tags search query takes too long ? - big forum

AI-generated summary

The original poster, veer, experiences slow query times when searching for multiple tags on a large forum with 0.5 million topics and 10,000 tags. cpradio analyzes the issue using the provided mini profiler details and suggests that the problem lies in the use of IN and performing it three times for each tag. They also recommend using =, instead of IN, when searching for a single tag. cpradio mentions that the current search functionality does not support an efficient way to perform AND operations for multiple tags, which is a feature being requested on Meta Discourse. Meanwhile, clay proposes a URL structure to support searching by multiple tags, but Falco points out that a similar structure already exists, such as <https://meta.discourse.org/tags/intersection/docker/email>, which clay finds helpful.

Its a very big forum, around 0.5 million topics and 10 thousands tags, which are on each topic, 3-4 in number.
Multiple tags search query takes very very long time, how to fix this ?

Can you paste in the slow query using mini profiler

here is the complete miniprofiler details.
please see
http://trail.lawus1.com/search.html

I see. So in this example, it definitely is requiring each tag individually. I imagine the performance impact is the use of IN and then doing it 3 times (one for each tag).

I also wonder if the search can be smarter about this? Only use IN when multiple tags are provided, otherwise use =

If you alter your search to tags:wa,gastroenterology,female does it work better? Granted, it changes the query, as it won’t be topics that have all three, but topics that have any of the three.

Right now tags does not have a performant way to do AND and that is being requested at

ping @alehandrof, you might find this interesting

I’ll just throw in some food for thought here. It might be nice to have a URL structure to support searching by multiple tags.

This could be wordpress AND embedding

https://meta.discourse.org/tags/wordpress&embedding

This could be wordpress OR embedding

https://meta.discourse.org/tags/wordpress|embedding

https://meta.discourse.org/tags/intersection/docker/email

Cool! I didn’t know you could do that. Thanks!