| 1 | -- One page of notifications, planned the way our servers plan it: make plan Q=inbox U=1 |
| 2 | set plan_cache_mode = force_generic_plan; |
| 3 | prepare inbox(bigint, bigint, int) as |
| 4 | select n.id, n.kind, a.handle, n.post_id, n.created_at, n.id > u.seen_notification, |
| 5 | p.body |
| 6 | from notifications n |
| 7 | join users a on a.id = n.actor_id |
| 8 | join users u on u.id = n.user_id |
| 9 | join posts p on p.id = n.post_id |
| 10 | where n.user_id = $1 and n.id < $2 |
| 11 | order by n.id desc |
| 12 | limit $3; |
| 13 | explain (analyze, timing off) execute inbox(:user, 9223372036854775807, 21); |