# SQL query taking too much time to run

**URL:** https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583
**Category:** Support
**Created:** [2015年十二月11日 17:52 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583 "2015-12-11T17:52:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sergiolopes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sergiolopes/32/122065_2.png) [@sergiolopes](https://meta.discourse.org/u/sergiolopes)
#### Post date: [2015年十二月11日 17:52 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583/1 "2015-12-11T17:52:56Z")

</div>

We are migrating an old forum with 1.6 million messages to Discourse. When opening the home page as logged in user, there is a super query taking too long to execute (many seconds). We are still testing so there is only one user - me.

We are on AWS using RDS. On our default machine, it took more than 13s to return this query. I updated to a xlarge super machine for testing and still this query take more than 500ms.

Is this normal? Any advice?

 ![](https://global.discourse-cdn.com/meta/original/3X/2/5/25a09810e3f14ad5bb65f1e7b5266bc663a4adcf.png)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2015年十二月11日 17:58 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583/2 "2015-12-11T17:58:19Z")

</div>

More than 500ms isn’t outside the realms of normal. Do you have unusual permissions on the categories? Have you tested with an anonymous or new user rather than a staff user?

---

<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: [2015年十二月11日 18:21 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583/3 "2015-12-11T18:21:09Z")

</div>

This query has been rewritten, can you update to latest?

---

<div class="post-metadata">

### Author: ![sergiolopes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sergiolopes/32/122065_2.png) [@sergiolopes](https://meta.discourse.org/u/sergiolopes)
#### Post date: [2015年十二月11日 18:24 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583/4 "2015-12-11T18:24:47Z")

</div>

Thanks guys!  
We did more tests here and it seems that as an annonymous user everything is ok. SQL take no more than 30ms.

But logging in both as an admin or as a normal user, the query take too long. Usually more than 1 second, and at least 500ms.

We are using Discourse 1.4.3 (latest stable?) at [http://discourse.guj.com.br:3000](http://discourse.guj.com.br:3000) . @sam, do you recommend updating to 1.5.0-beta6?

---

<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: [2015年十二月11日 18:25 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583/5 "2015-12-11T18:25:57Z")

</div>

Yes, switch to the beta branch at least, let me know what happens

---

<div class="post-metadata">

### Author: ![sergiolopes](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sergiolopes/32/122065_2.png) [@sergiolopes](https://meta.discourse.org/u/sergiolopes)
#### Post date: [2015年十二月11日 18:43 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583/6 "2015-12-11T18:43:12Z")

</div>

Fantastic! We updated to beta and things got much better. ~60ms to ~100ms for logged in users and ~10ms for anonymous users.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2015年十二月11日 18:50 UTC](https://meta.discourse.org/t/sql-query-taking-too-much-time-to-run/36583/7 "2015-12-11T18:50:26Z")

</div>


