Skip to content

Instantly share code, notes, and snippets.

@unarist
Created November 15, 2017 14:17
Show Gist options
  • Save unarist/6835ccd70296fa5f8d12e49340da3e93 to your computer and use it in GitHub Desktop.
Save unarist/6835ccd70296fa5f8d12e49340da3e93 to your computer and use it in GitHub Desktop.
SELECT id FROM statuses
WHERE "statuses"."visibility" = 0 
AND (statuses.reblog_of_id IS NULL)
AND (statuses.reply = FALSE OR statuses.in_reply_to_account_id = statuses.account_id)
AND statuses.account_id IN (
  SELECT target_account_id FROM follows WHERE account_id IN (
    SELECT target_account_id FROM follows WHERE account_id = 100
  )
)
Hash Join  (cost=1573.60..2361.43 rows=3835 width=8) (actual time=12.747..16.038 rows=2921 loops=1)
  Output: statuses.id
  Hash Cond: (statuses.account_id = follows.target_account_id)
  Buffers: shared hit=734
  ->  Seq Scan on public.statuses  (cost=0.00..730.33 rows=3835 width=16) (actual time=0.020..2.812 rows=3387 loops=1)
        Output: statuses.id, statuses.account_id
        Filter: ((statuses.reblog_of_id IS NULL) AND ((NOT statuses.reply) OR (statuses.in_reply_to_account_id = statuses.account_id)) AND (statuses.visibility = 0))
        Rows Removed by Filter: 7636
        Buffers: shared hit=566
  ->  Hash  (cost=1563.66..1563.66 rows=795 width=8) (actual time=12.714..12.714 rows=338 loops=1)
        Output: follows.target_account_id
        Buckets: 1024  Batches: 1  Memory Usage: 22kB
        Buffers: shared hit=168
        ->  HashAggregate  (cost=1555.71..1563.66 rows=795 width=8) (actual time=12.644..12.671 rows=338 loops=1)
              Output: follows.target_account_id
              Group Key: follows.target_account_id
              Buffers: shared hit=168
              ->  Nested Loop  (cost=0.84..1479.80 rows=30364 width=8) (actual time=3.409..12.265 rows=2350 loops=1)
                    Output: follows.target_account_id
                    Buffers: shared hit=168
                    ->  Index Only Scan using index_follows_on_account_id_and_target_account_id on public.follows follows_1  (cost=0.42..7.22 rows=160 width=8) (actual time=2.027..2.034 rows=50 loops=1)
                          Output: follows_1.account_id, follows_1.target_account_id
                          Index Cond: (follows_1.account_id = 100)
                          Heap Fetches: 0
                          Buffers: shared hit=4
                    ->  Index Only Scan using index_follows_on_account_id_and_target_account_id on public.follows  (cost=0.42..7.30 rows=190 width=16) (actual time=0.193..0.200 rows=47 loops=50)
                          Output: follows.account_id, follows.target_account_id
                          Index Cond: (follows.account_id = follows_1.target_account_id)
                          Heap Fetches: 0
                          Buffers: shared hit=164
Planning time: 1.027 ms
Execution time: 16.208 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment