# Mysterious entries in topic\_users table

**URL:** https://meta.discourse.org/t/mysterious-entries-in-topic-users-table/44080
**Category:** Bug
**Created:** [2016年五月11日 20:17 UTC](https://meta.discourse.org/t/mysterious-entries-in-topic-users-table/44080 "2016-05-11T20:17:39Z")
**Posts on this page:** 4
**Page:** 2

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2016年五月14日 15:34 UTC](https://meta.discourse.org/t/mysterious-entries-in-topic-users-table/44080/21 "2016-05-14T15:34:20Z")

</div>

I was thinking something like

```sql
DELETE FROM topic_users
      USING topic_users tu
  LEFT JOIN users u ON u.id = tu.user_id
      WHERE u.id IS NULL
        AND topic_users.id = tu.id

```

**EDIT:** it’s pushed now 😉

[https://github.com/discourse/discourse/commit/aebb15337b2ecfa8611b7dd7616eb3528dc75e3c](https://github.com/discourse/discourse/commit/aebb15337b2ecfa8611b7dd7616eb3528dc75e3c)

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [2016年五月14日 15:57 UTC](https://meta.discourse.org/t/mysterious-entries-in-topic-users-table/44080/22 "2016-05-14T15:57:25Z")

</div>

If I’m reading the query right that looks like it would be the safest in terms of not doing any wrong deletions.  
And better than my MAX which assumes NULL and may in fact miss some NULL

I don’t imagine leaving any bogus rows would have much effect on performance.

The only possible problem that I can think of might be if a member has set notification level for something, the corresponding topic would be reset to Normal  
And I don’t know for certain if that could happen, though as the bogus gets added last I think it might be possible.

---

<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: [2016年五月16日 21:22 UTC](https://meta.discourse.org/t/mysterious-entries-in-topic-users-table/44080/23 "2016-05-16T21:22:34Z")

</div>

Fantastic work @Mittineague and @fefrei tracking this down. Gold ⭐ for both of you!

---

<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: [2016年五月16日 22:33 UTC](https://meta.discourse.org/t/mysterious-entries-in-topic-users-table/44080/24 "2016-05-16T22:33:08Z")

</div>



[上一頁](https://meta.discourse.org/t/mysterious-entries-in-topic-users-table/44080.md?page=1)
