Gerhard Schlager
71849242fa
PERF: Speed up moving posts on large databases
Old exection plan:
```
Delete on post_replies pr (cost=6.59..20462.62 rows=2254 width=24) (actual time=2.580..2.580 rows=0 loops=1)
-> Nested Loop (cost=6.59..20462.62 rows=2254 width=24) (actual time=0.086..2.557 rows=4 loops=1)
Join Filter: (p.topic_id <> r.topic_id)
Rows Removed by Join Filter: 328
-> Nested Loop (cost=6.16..16845.77 rows=2254 width=26) (actual time=0.020..1.886 rows=332 loops=1)
-> Nested Loop (cost=5.74..13257.09 rows=2254 width=20) (actual time=0.016..1.361 rows=332 loops=1)
-> Seq Scan on moved_posts mp (cost=0.00..19.70 rows=970 width=10) (actual time=0.002..0.028 rows=263 loops=1)
-> Bitmap Heap Scan on post_replies pr (cost=5.74..13.63 rows=2 width=14) (actual time=0.004..0.005 rows=1 loops=263)
Recheck Cond: ((reply_post_id = mp.old_post_id) OR (post_id = mp.old_post_id))
Heap Blocks: exact=278
-> BitmapOr (cost=5.74..5.74 rows=2 width=0) (actual time=0.004..0.004 rows=0 loops=263)
-> Bitmap Index Scan on index_post_replies_on_reply_post_id (cost=0.00..2.87 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=263)
Index Cond: (reply_post_id = mp.old_post_id)
-> Bitmap Index Scan on index_post_replies_on_post_id_and_reply_post_id (cost=0.00..2.87 rows=1 width=0) (actual time=0.002..0.002 rows=1 loops=263)
Index Cond: (post_id = mp.old_post_id)
-> Index Scan using posts_pkey on posts p (cost=0.42..1.59 rows=1 width=14) (actual time=0.001..0.001 rows=1 loops=332)
Index Cond: (id = pr.post_id)
-> Index Scan using posts_pkey on posts r (cost=0.42..1.59 rows=1 width=14) (actual time=0.001..0.002 rows=1 loops=332)
Index Cond: (id = pr.reply_post_id)
Planning Time: 0.305 ms
Execution Time: 2.600 ms
```
New execution plan:
```
Delete on post_replies pr (cost=15.34..6538275.37 rows=364157 width=12) (actual time=1.961..1.961 rows=0 loops=1)
-> Nested Loop (cost=15.34..6538275.37 rows=364157 width=12) (actual time=0.048..1.827 rows=187 loops=1)
-> Seq Scan on moved_posts mp (cost=0.00..19.70 rows=970 width=10) (actual time=0.004..0.029 rows=188 loops=1)
-> Bitmap Heap Scan on post_replies pr (cost=15.34..6736.72 rows=375 width=14) (actual time=0.009..0.009 rows=1 loops=188)
Recheck Cond: ((reply_post_id = mp.old_post_id) OR (post_id = mp.old_post_id))
Filter: ((SubPlan 1) <> (SubPlan 2))
Heap Blocks: exact=187
-> BitmapOr (cost=15.34..15.34 rows=377 width=0) (actual time=0.003..0.003 rows=0 loops=188)
-> Bitmap Index Scan on index_post_replies_on_reply_post_id (cost=0.00..4.33 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=188)
Index Cond: (reply_post_id = mp.old_post_id)
-> Bitmap Index Scan on index_post_replies_on_post_id_and_reply_post_id (cost=0.00..10.82 rows=376 width=0) (actual time=0.001..0.001 rows=0 loops=188)
Index Cond: (post_id = mp.old_post_id)
SubPlan 1
-> Index Scan using posts_pkey on posts p (cost=0.43..8.45 rows=1 width=4) (actual time=0.002..0.002 rows=1 loops=187)
Index Cond: (id = pr.post_id)
SubPlan 2
-> Index Scan using posts_pkey on posts r (cost=0.43..8.45 rows=1 width=4) (actual time=0.002..0.003 rows=1 loops=187)
Index Cond: (id = pr.reply_post_id)
Planning Time: 0.136 ms
Execution Time: 1.990 ms
```
2020-02-04 12:30:43 +01:00
..
2020-01-21 15:32:06 +11:00
2019-08-13 16:53:16 +01:00
2019-10-03 21:48:56 +03:00
2019-12-03 10:05:53 +01:00
2019-08-28 12:37:42 +01:00
2019-05-13 09:31:32 +08:00
2019-05-29 14:26:24 +10:00
2019-12-12 11:45:00 +00:00
2019-12-03 10:05:53 +01:00
2019-10-02 14:01:53 +10:00
2019-10-17 16:58:21 +11:00
2019-10-17 16:58:21 +11:00
2019-05-13 09:31:32 +08:00
2019-10-02 14:01:53 +10:00
2020-01-16 17:48:47 +01:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2020-01-14 14:26:49 +00:00
2019-12-11 14:04:02 +10:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-12-03 10:05:53 +01:00
2019-10-23 10:30:43 +01:00
2020-02-03 10:40:02 -08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-11-19 10:21:06 +00:00
2020-01-27 15:28:56 +01:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-12-10 11:48:39 +11:00
2019-05-13 09:31:32 +08:00
2019-11-29 15:49:08 +00:00
2019-10-02 14:01:53 +10:00
2019-09-11 15:18:17 -04:00
2019-11-27 16:11:49 +11:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2020-01-02 11:38:14 +11:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-10-23 19:22:33 -04:00
2019-05-13 15:16:53 +05:30
2019-12-12 12:49:21 +10:00
2019-11-12 09:49:02 -06:00
2019-05-13 09:31:32 +08:00
2019-08-30 15:06:23 +10:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-12-03 10:05:53 +01:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-10-02 14:01:53 +10:00
2020-01-15 11:21:58 +01:00
2019-05-13 09:31:32 +08:00
2019-05-14 17:44:53 +02:00
2019-05-13 09:31:32 +08:00
2019-10-21 12:08:20 +01:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-12-17 10:13:49 -05:00
2020-01-27 15:28:56 +01:00
2019-05-13 09:31:32 +08:00
2019-06-03 10:41:00 +01:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-05-13 09:31:32 +08:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-12-05 20:35:39 +05:30
2019-10-25 11:57:34 +11:00
2019-05-13 09:31:32 +08:00
2020-02-03 12:28:45 -05:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-10-02 14:01:53 +10:00
2019-10-21 12:08:20 +01:00
2019-10-02 14:01:53 +10:00
2019-05-13 15:24:24 +01:00
2019-05-13 09:31:32 +08:00
2020-02-04 12:30:43 +01:00
2019-05-13 09:31:32 +08:00
2020-01-17 17:24:49 +01:00
2019-10-02 14:01:53 +10:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2020-01-31 10:23:24 -03:00
2019-05-13 09:31:32 +08:00
2020-02-03 13:41:18 -05:00
2019-10-02 14:01:53 +10:00
2019-05-13 09:31:32 +08:00
2019-10-21 12:08:20 +01:00
2019-11-28 13:13:29 +11:00
2019-10-02 14:01:53 +10:00
2019-11-27 16:11:49 +11:00
2020-01-09 12:32:05 -05:00
2020-01-06 13:38:23 -03:00
2019-05-13 09:31:32 +08:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2020-01-17 11:59:38 -03:00
2019-10-02 14:01:53 +10:00
2020-01-29 15:38:27 -03:00
2020-01-09 12:04:17 -05:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-12-03 10:05:53 +01:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-10-04 15:57:17 +10:00
2019-12-03 10:05:53 +01:00
2019-07-01 14:03:03 +02:00
2019-10-02 14:01:53 +10:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-06-27 17:53:26 +10:00
2019-05-13 09:31:32 +08:00
2019-12-04 13:33:51 -05:00
2020-01-21 19:23:08 +02:00
2019-11-12 14:30:19 +00:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-12-09 14:24:38 +11:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-10-02 14:01:53 +10:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2020-01-23 12:01:10 +10:00
2019-05-29 14:26:24 +10:00
2019-11-27 12:36:19 +11:00
2019-05-13 09:31:32 +08:00
2019-12-13 11:51:40 -05:00
2019-05-13 09:31:32 +08:00
2019-12-03 10:05:53 +01:00
2019-12-04 17:13:20 +11:00
2019-11-14 11:16:13 +11:00
2019-05-13 09:31:32 +08:00
2019-11-15 15:11:09 -05:00
2019-05-13 09:31:32 +08:00
2019-10-02 14:01:53 +10:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-11-19 10:10:14 -07:00
2020-01-06 18:22:42 +00:00
2019-10-21 12:08:20 +01:00
2019-12-03 10:05:53 +01:00
2020-01-23 12:01:10 +10:00
2019-12-10 11:48:39 +11:00
2019-12-20 15:25:21 -08:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-05-13 09:31:32 +08:00
2020-01-30 16:19:14 +10:00
2020-01-27 15:28:56 +01:00
2019-11-14 15:10:51 -05:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-11-27 12:39:31 +00:00
2019-10-02 14:01:53 +10:00
2020-01-14 14:26:49 +00:00
2019-05-13 09:31:32 +08:00
2020-01-09 17:08:55 +01:00
2019-10-02 14:01:53 +10:00
2019-07-25 19:41:25 +05:30
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-11-28 07:32:17 +10:00
2019-05-13 09:31:32 +08:00
2019-12-03 10:05:53 +01:00
2019-12-03 10:05:53 +01:00
2020-01-27 15:28:56 +01:00
2019-05-13 09:31:32 +08:00
2019-10-28 11:01:47 +00:00
2020-01-10 10:45:56 +10:00
2019-10-17 16:58:22 +11:00
2020-01-09 17:08:55 +01:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2019-05-13 09:31:32 +08:00
2020-02-03 14:14:32 -05:00
2019-10-02 14:01:53 +10:00
2019-10-02 14:01:53 +10:00
2019-12-03 10:05:53 +01:00
2019-08-15 14:47:25 -04:00
2019-05-13 09:31:32 +08:00
2019-08-26 10:33:26 -03:00