| 1 | -- A user's posts, planned the way our servers plan it: make plan Q=posts U=1 |
| 2 | set plan_cache_mode = force_generic_plan; |
| 3 | prepare posts(text, bigint, int, bigint) as |
| 4 | select p.id, p.user_id, p.body, p.created_at, u.handle, p.likes_count, |
| 5 | exists (select 1 from likes where post_id = p.id and user_id = $4) |
| 6 | from posts p |
| 7 | join users u on u.id = p.user_id |
| 8 | where p.user_id = (select id from users where handle = $1) and p.id < $2 |
| 9 | order by p.id desc |
| 10 | limit $3; |
| 11 | explain (analyze, timing off) execute posts('user' || :user, 9223372036854775807, 21, 42); |