# Query causing 400% CPU Load

**URL:** <https://meta.discourse.org/t/query-causing-400-cpu-load/285542>\
**Category:** Bug\
**Tags:** chat\
**Created:** [November 15, 2023, 10:46am UTC](https://meta.discourse.org/t/query-causing-400-cpu-load/285542 "2023-11-15T10:46:49Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![andrei](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrei/32/205142_2.png) [@andrei](https://meta.discourse.org/u/andrei)\
**Post date:** [December 1, 2023, 8:00pm UTC](https://meta.discourse.org/t/query-causing-400-cpu-load/285542/26 "2023-12-01T20:00:57Z")

</div>

@sok777 thank you for sharing the query plan! It’s very helpful.

Your instance contains a big amount of users _and_ a big amount of the `user_chat_channel_memberships records` (as you shared [here](https://meta.discourse.org/t/query-causing-400-cpu-load/285542/16)).

Before you shared the test plan, I tried to reproduce the problem on sites with big amount of users, but the query worked well. Now, I see that those sites don’t have a big amount of `user_chat_channel_memberships`, very likely this is what’s specific about your site and what caused so serious problems in your case.

As I understand, you don’t have problems now, because you removed all mentions at some point, but I would expect this query to become problematic again at some point, even with small amount of mentions. So I will be optimizing it in any case.

I’m currently working on fixing the underling problem that caused creating huge loads of `chat_mention` records in database. While it’s in progress, it’s important to keep @ all and @ here in the watched words. I’ll post an update here when I take care of that, and after that I’ll make sure to optimize this query.

---

_[View the full topic](https://meta.discourse.org/t/query-causing-400-cpu-load/285542)._
