# Multiple Tags search query takes too long ? - big forum

**URL:** <https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023>\
**Category:** Support\
**Created:** [2017年一月19日 12:33 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023 "2017-01-19T12:33:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![veer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/veer/32/69391_2.png) [@veer](https://meta.discourse.org/u/veer)\
**Post date:** [2017年一月19日 12:33 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/1 "2017-01-19T12:33:11Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2017年一月19日 13:16 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/2 "2017-01-19T13:16:44Z")

</div>

Can you paste in the slow query using mini profiler

---

<div class="post-metadata">

**Author:** ![veer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/veer/32/69391_2.png) [@veer](https://meta.discourse.org/u/veer)\
**Post date:** [2017年一月20日 16:05 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/5 "2017-01-20T16:05:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)\
**Post date:** [2017年一月20日 16:13 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/6 "2017-01-20T16:13:09Z")

</div>

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

> [@Does multiple tag search support AND vs OR?](https://meta.discourse.org/t/does-multiple-tag-search-support-and-vs-or/56041):
>
> I think there is a bug when searching multiple tags. Here is the strange result I got on my Discourse: Based on the search, there should be 8 results. But it displays 9. The 2nd result is correct, but not the 1st one. I wonder if the issue with the hyphen, since the mistaken result also contains the a tag that includes some of search terms ( -reports). The issue does not appear when searching for just committee-reports.

ping @alehandrof, you might find this interesting

---

<div class="post-metadata">

**Author:** ![clay](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/clay/32/102156_2.png) [@clay](https://meta.discourse.org/u/clay)\
**Post date:** [2017年四月7日 13:07 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/7 "2017-04-07T13:07:46Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2017年四月7日 16:08 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/8 "2017-04-07T16:08:02Z")

</div>

> [@clay](#):
>
> 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.

[https://meta.discourse.org/tags/intersection/docker/email](https://meta.discourse.org/tags/intersection/docker/email)

---

<div class="post-metadata">

**Author:** ![clay](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/clay/32/102156_2.png) [@clay](https://meta.discourse.org/u/clay)\
**Post date:** [2017年四月7日 16:19 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/9 "2017-04-07T16:19:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2019年五月22日 23:40 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/10 "2019-05-22T23:40:08Z")

</div>



---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [2019年五月24日 07:18 UTC](https://meta.discourse.org/t/multiple-tags-search-query-takes-too-long-big-forum/56023/11 "2019-05-24T07:18:16Z")

</div>


