| 1 | -- The unread count, for one user: make explain Q=unread U=1 |
| 2 | -- First the way the API asks: it stops counting at a hundred. |
| 3 | explain (analyze, costs off, timing off) |
| 4 | select count(*) from ( |
| 5 | select 1 |
| 6 | from notifications |
| 7 | where user_id = :user and id > (select seen_notification from users where id = :user) |
| 8 | limit 100 |
| 9 | ) unseen; |
| 10 | |
| 11 | -- And then without the limit: every unread notification is counted. |
| 12 | explain (analyze, costs off, timing off) |
| 13 | select count(*) |
| 14 | from notifications |
| 15 | where user_id = :user and id > (select seen_notification from users where id = :user); |