Skip to content

Instantly share code, notes, and snippets.

@sunaurus
Last active July 18, 2023 08:23
Show Gist options
  • Save sunaurus/856e03165bb0c0010505afeebde45230 to your computer and use it in GitHub Desktop.
Save sunaurus/856e03165bb0c0010505afeebde45230 to your computer and use it in GitHub Desktop.
Front page "subscribed" feed query plans

Original query

Limit  (cost=1276.73..1276.78 rows=20 width=3173) (actual time=3501.235..3501.302 rows=20 loops=1)
  ->  Sort  (cost=1276.73..1277.75 rows=408 width=3173) (actual time=3501.234..3501.296 rows=20 loops=1)
"        Sort Key: post_aggregates.featured_local DESC, post_aggregates.hot_rank DESC"
        Sort Method: top-N heapsort  Memory: 101kB
        ->  Nested Loop  (cost=21.91..1265.87 rows=408 width=3173) (actual time=33.530..3351.905 rows=25841 loops=1)
              ->  Nested Loop Left Join  (cost=21.47..1239.54 rows=395 width=3173) (actual time=29.344..3280.371 rows=25841 loops=1)
                    ->  Nested Loop Left Join  (cost=21.05..1053.98 rows=395 width=3165) (actual time=29.132..2165.523 rows=25841 loops=1)
                          ->  Hash Anti Join  (cost=20.62..804.43 rows=395 width=3163) (actual time=1.154..1697.775 rows=25841 loops=1)
                                Hash Cond: (post.community_id = community_block.community_id)
                                ->  Nested Loop Anti Join  (cost=15.32..794.10 rows=398 width=3163) (actual time=0.987..1656.891 rows=25841 loops=1)
                                      Join Filter: (post.creator_id = person_block.target_id)
                                      ->  Nested Loop Left Join  (cost=15.04..778.17 rows=426 width=3143) (actual time=0.926..1613.294 rows=25841 loops=1)
                                            ->  Hash Left Join  (cost=14.62..569.60 rows=426 width=3123) (actual time=0.866..700.160 rows=25841 loops=1)
                                                  Hash Cond: (post.id = post_saved.post_id)
                                                  ->  Hash Left Join  (cost=10.57..564.44 rows=426 width=3103) (actual time=0.704..662.371 rows=25841 loops=1)
                                                        Hash Cond: ((post.community_id = community_person_ban.community_id) AND (post.creator_id = community_person_ban.person_id))
                                                        ->  Nested Loop  (cost=1.85..553.48 rows=426 width=3075) (actual time=0.359..621.815 rows=25841 loops=1)
                                                              ->  Nested Loop  (cost=1.43..342.28 rows=426 width=2155) (actual time=0.312..394.494 rows=25841 loops=1)
                                                                    ->  Nested Loop  (cost=1.00..138.38 rows=430 width=2081) (actual time=0.244..136.705 rows=25841 loops=1)
                                                                          ->  Nested Loop  (cost=0.58..54.93 rows=20 width=1168) (actual time=0.154..14.980 rows=86 loops=1)
                                                                                ->  Index Scan using idx_community_follower_person on community_follower  (cost=0.29..11.83 rows=20 width=21) (actual time=0.079..12.723 rows=86 loops=1)
                                                                                      Index Cond: ((person_id IS NOT NULL) AND (person_id = 2))
                                                                                ->  Index Scan using community_pkey on community  (cost=0.29..2.15 rows=1 width=1147) (actual time=0.019..0.019 rows=1 loops=86)
                                                                                      Index Cond: (id = community_follower.community_id)
                                                                          ->  Index Scan using idx_post_community on post  (cost=0.42..3.43 rows=74 width=913) (actual time=0.100..0.996 rows=300 loops=86)
                                                                                Index Cond: (community_id = community.id)
                                                                    ->  Index Scan using post_aggregates_post_id_key on post_aggregates  (cost=0.42..0.47 rows=1 width=74) (actual time=0.008..0.008 rows=1 loops=25841)
                                                                          Index Cond: (post_id = post.id)
                                                              ->  Index Scan using person__pkey on person  (cost=0.42..0.50 rows=1 width=920) (actual time=0.006..0.006 rows=1 loops=25841)
                                                                    Index Cond: (id = post.creator_id)
                                                        ->  Hash  (cost=4.69..4.69 rows=269 width=28) (actual time=0.272..0.273 rows=270 loops=1)
                                                              Buckets: 1024  Batches: 1  Memory Usage: 25kB
                                                              ->  Seq Scan on community_person_ban  (cost=0.00..4.69 rows=269 width=28) (actual time=0.025..0.068 rows=270 loops=1)
                                                  ->  Hash  (cost=4.01..4.01 rows=3 width=20) (actual time=0.077..0.077 rows=1 loops=1)
                                                        Buckets: 1024  Batches: 1  Memory Usage: 9kB
                                                        ->  Index Scan using idx_post_saved_person_id on post_saved  (cost=0.29..4.01 rows=3 width=20) (actual time=0.058..0.060 rows=1 loops=1)
                                                              Index Cond: (person_id = 2)
                                            ->  Index Scan using post_read_post_id_person_id_key on post_read  (cost=0.43..0.49 rows=1 width=20) (actual time=0.033..0.033 rows=0 loops=25841)
                                                  Index Cond: ((post_id = post.id) AND (person_id = 2))
                                      ->  Materialize  (cost=0.28..3.15 rows=2 width=20) (actual time=0.000..0.000 rows=0 loops=25841)
                                            ->  Index Scan using idx_person_block_person on person_block  (cost=0.28..3.14 rows=2 width=20) (actual time=0.037..0.037 rows=0 loops=1)
                                                  Index Cond: (person_id = 2)
                                ->  Hash  (cost=5.18..5.18 rows=9 width=4) (actual time=0.064..0.115 rows=0 loops=1)
                                      Buckets: 1024  Batches: 1  Memory Usage: 8kB
                                      ->  Index Only Scan using community_block_person_id_community_id_key on community_block  (cost=0.29..5.18 rows=9 width=4) (actual time=0.064..0.064 rows=0 loops=1)
                                            Index Cond: (person_id = 2)
                                            Heap Fetches: 0
                          ->  Index Scan using post_like_post_id_person_id_key on post_like  (cost=0.43..0.63 rows=1 width=6) (actual time=0.016..0.016 rows=0 loops=25841)
                                Index Cond: ((post_id = post.id) AND (person_id = 2))
                    ->  Index Scan using person_post_aggregates_person_id_post_id_key on person_post_aggregates  (cost=0.42..0.47 rows=1 width=12) (actual time=0.041..0.041 rows=0 loops=25841)
                          Index Cond: ((person_id = 2) AND (post_id = post.id))
              ->  Memoize  (cost=0.44..0.48 rows=1 width=4) (actual time=0.001..0.001 rows=1 loops=25841)
                    Cache Key: post.language_id
                    Cache Mode: logical
                    Hits: 25820  Misses: 21  Evictions: 0  Overflows: 0  Memory Usage: 3kB
                    ->  Index Only Scan using local_user_language_local_user_id_language_id_key on local_user_language  (cost=0.43..0.47 rows=1 width=4) (actual time=0.318..0.318 rows=1 loops=21)
                          Index Cond: ((local_user_id = 1) AND (language_id = post.language_id) AND (language_id IS NOT NULL))
                          Heap Fetches: 47
Planning Time: 134.066 ms
Execution Time: 3503.256 ms

Joining community on post_aggregates

Limit  (cost=4.70..1026.70 rows=20 width=3173) (actual time=0.265..5.081 rows=20 loops=1)
  ->  Nested Loop  (cost=4.70..226787.36 rows=4438 width=3173) (actual time=0.263..5.076 rows=20 loops=1)
        ->  Nested Loop Left Join  (cost=4.27..224756.63 rows=4298 width=3173) (actual time=0.229..4.884 rows=20 loops=1)
              ->  Nested Loop Left Join  (cost=3.84..222737.70 rows=4298 width=3165) (actual time=0.212..4.795 rows=20 loops=1)
                    ->  Nested Loop Anti Join  (cost=3.41..220023.20 rows=4298 width=3163) (actual time=0.193..4.666 rows=20 loops=1)
                          Join Filter: (post.community_id = community_block.community_id)
                          ->  Nested Loop Anti Join  (cost=3.12..219432.77 rows=4335 width=3163) (actual time=0.180..4.637 rows=20 loops=1)
                                Join Filter: (post.creator_id = person_block.target_id)
                                ->  Nested Loop Left Join  (cost=2.84..219290.42 rows=4640 width=3143) (actual time=0.168..4.607 rows=20 loops=1)
                                      ->  Nested Loop Left Join  (cost=2.42..217018.85 rows=4640 width=3123) (actual time=0.148..4.494 rows=20 loops=1)
                                            Join Filter: (post.id = post_saved.post_id)
                                            Rows Removed by Join Filter: 20
                                            ->  Nested Loop Left Join  (cost=2.13..216806.04 rows=4640 width=3103) (actual time=0.129..4.432 rows=20 loops=1)
                                                  ->  Nested Loop  (cost=1.98..216028.79 rows=4640 width=3075) (actual time=0.117..4.374 rows=20 loops=1)
                                                        ->  Nested Loop  (cost=1.56..213728.80 rows=4640 width=2155) (actual time=0.098..4.201 rows=20 loops=1)
                                                              ->  Nested Loop  (cost=1.27..212278.01 rows=4658 width=1012) (actual time=0.083..4.075 rows=29 loops=1)
                                                                    ->  Nested Loop  (cost=0.84..201277.54 rows=353273 width=991) (actual time=0.055..2.631 rows=368 loops=1)
                                                                          ->  Index Scan using idx_post_aggregates_featured_local_hot on post_aggregates  (cost=0.42..16835.52 rows=353273 width=78) (actual time=0.033..0.701 rows=368 loops=1)
                                                                          ->  Index Scan using post_pkey on post  (cost=0.42..0.52 rows=1 width=913) (actual time=0.004..0.004 rows=1 loops=368)
                                                                                Index Cond: (id = post_aggregates.post_id)
                                                                    ->  Memoize  (cost=0.43..0.46 rows=1 width=21) (actual time=0.004..0.004 rows=0 loops=368)
                                                                          Cache Key: post.community_id
                                                                          Cache Mode: logical
                                                                          Hits: 162  Misses: 206  Evictions: 0  Overflows: 0  Memory Usage: 15kB
                                                                          ->  Index Scan using community_follower_community_id_person_id_key on community_follower  (cost=0.42..0.45 rows=1 width=21) (actual time=0.005..0.005 rows=0 loops=206)
                                                                                Index Cond: ((community_id = post.community_id) AND (person_id IS NOT NULL) AND (person_id = 2))
                                                              ->  Index Scan using community_pkey on community  (cost=0.29..0.31 rows=1 width=1147) (actual time=0.003..0.003 rows=1 loops=29)
                                                                    Index Cond: (id = post_aggregates.community_id)
                                                        ->  Index Scan using person__pkey on person  (cost=0.42..0.50 rows=1 width=920) (actual time=0.007..0.007 rows=1 loops=20)
                                                              Index Cond: (id = post.creator_id)
                                                  ->  Index Scan using community_person_ban_community_id_person_id_key on community_person_ban  (cost=0.15..0.17 rows=1 width=28) (actual time=0.002..0.002 rows=0 loops=20)
                                                        Index Cond: ((community_id = post.community_id) AND (person_id = post.creator_id))
                                            ->  Materialize  (cost=0.29..4.02 rows=3 width=20) (actual time=0.001..0.002 rows=1 loops=20)
                                                  ->  Index Scan using idx_post_saved_person_id on post_saved  (cost=0.29..4.01 rows=3 width=20) (actual time=0.013..0.014 rows=1 loops=1)
                                                        Index Cond: (person_id = 2)
                                      ->  Index Scan using post_read_post_id_person_id_key on post_read  (cost=0.43..0.49 rows=1 width=20) (actual time=0.005..0.005 rows=0 loops=20)
                                            Index Cond: ((post_id = post.id) AND (person_id = 2))
                                ->  Materialize  (cost=0.28..3.15 rows=2 width=20) (actual time=0.001..0.001 rows=0 loops=20)
                                      ->  Index Scan using idx_person_block_person on person_block  (cost=0.28..3.14 rows=2 width=20) (actual time=0.008..0.009 rows=0 loops=1)
                                            Index Cond: (person_id = 2)
                          ->  Materialize  (cost=0.29..5.23 rows=9 width=4) (actual time=0.001..0.001 rows=0 loops=20)
                                ->  Index Only Scan using community_block_person_id_community_id_key on community_block  (cost=0.29..5.18 rows=9 width=4) (actual time=0.009..0.009 rows=0 loops=1)
                                      Index Cond: (person_id = 2)
                                      Heap Fetches: 0
                    ->  Index Scan using post_like_post_id_person_id_key on post_like  (cost=0.43..0.63 rows=1 width=6) (actual time=0.005..0.005 rows=0 loops=20)
                          Index Cond: ((post_id = post.id) AND (person_id = 2))
              ->  Index Scan using person_post_aggregates_person_id_post_id_key on person_post_aggregates  (cost=0.42..0.47 rows=1 width=12) (actual time=0.003..0.003 rows=0 loops=20)
                    Index Cond: ((person_id = 2) AND (post_id = post.id))
        ->  Index Only Scan using local_user_language_local_user_id_language_id_key on local_user_language  (cost=0.43..0.47 rows=1 width=4) (actual time=0.006..0.006 rows=1 loops=20)
              Index Cond: ((local_user_id = 1) AND (language_id = post.language_id) AND (language_id IS NOT NULL))
              Heap Fetches: 60
Planning Time: 68.385 ms
Execution Time: 5.539 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment