By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
12 rows affected
| conversation_id | last_message_content | last_message_at |
|---|---|---|
| 1 | msg13 | 2021-12-12 |
| 3 | msg32 | 2021-12-12 |
| 6 | msg61 | 2021-12-06 |
| 5 | msg51 | 2021-12-05 |
| 4 | msg41 | 2021-12-04 |
| QUERY PLAN |
|---|
| Limit (cost=426.92..427.02 rows=5 width=40) (actual time=0.016..0.093 rows=5 loops=1) |
| CTE cte |
| -> Recursive Union (cost=0.14..426.92 rows=101 width=72) (actual time=0.014..0.086 rows=5 loops=1) |
| -> Limit (cost=0.14..1.15 rows=1 width=72) (actual time=0.013..0.013 rows=1 loops=1) |
| -> Index Scan using idx1 on messages (cost=0.14..12.31 rows=12 width=72) (actual time=0.012..0.012 rows=1 loops=1) |
| -> Nested Loop (cost=0.14..42.38 rows=10 width=72) (actual time=0.013..0.016 rows=1 loops=4) |
| -> WorkTable Scan on cte c (cost=0.00..0.20 rows=10 width=36) (actual time=0.000..0.000 rows=1 loops=4) |
| -> Limit (cost=0.14..4.20 rows=1 width=72) (actual time=0.011..0.011 rows=1 loops=4) |
| -> Index Scan using idx1 on messages m (cost=0.14..8.26 rows=2 width=72) (actual time=0.010..0.010 rows=1 loops=4) |
| Index Cond: (created_at <= c.created_at) |
| Filter: (conversation_id <> ALL (c.latest_ids)) |
| Rows Removed by Filter: 2 |
| -> CTE Scan on cte (cost=0.00..2.02 rows=101 width=40) (actual time=0.015..0.079 rows=5 loops=1) |
| Planning Time: 0.229 ms |
| Execution Time: 0.210 ms |