# Improve performance of Topic load - ORDER BY RANDOM

**URL:** <https://meta.discourse.org/t/improve-performance-of-topic-load-order-by-random/25619>\
**Category:** Bug\
**Tags:** slow-sql\
**Created:** [Fevereiro 24, 2015, 4:48pm UTC](https://meta.discourse.org/t/improve-performance-of-topic-load-order-by-random/25619 "2015-02-24T16:48:29Z")\
**Posts on this page:** 1\
**Showing post:** 19

<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:** [Fevereiro 28, 2015, 3:01am UTC](https://meta.discourse.org/t/improve-performance-of-topic-load-order-by-random/25619/19 "2015-02-28T03:01:55Z")

</div>

> [@DeanMarkTaylor](#):
>
> CREATE INDEX idx\_topic\_load\_suggested\_for  
> ON topics  
> USING btree  
> (deleted\_at, visible, archetype COLLATE pg\_catalog.“default”, created\_at);

By default indexes in postgres are using btree so we don’t need that, also collation should be good so we don’t need that… What I want you to test is:

```plaintext
create index idx_topics_suggested_for
on topics (visible, created_at) 
where archetype <> 'private_message' and deleted_at is null

```

This is a bit odd cause we are ordering on bumped\_at so I would assume

```plaintext
create index idx_topics_suggested_for
on topics (bumped_at) 
where archetype <> 'private_message' and deleted_at is null and visible

```

Should work best, however admins see non-visible topics so perhaps adding it in makes sense.

What I am really struggling here with is why would you be adding deleted\_at to the actual index when the only valid value for it on selection is NULL. We are never ordering on deleted\_at

---

_[View the full topic](https://meta.discourse.org/t/improve-performance-of-topic-load-order-by-random/25619)._
