Skip to content

Instantly share code, notes, and snippets.

@tateisu
Created October 12, 2017 14:33
Show Gist options
  • Save tateisu/0cd25643e0ef3621f3535002268dbc8b to your computer and use it in GitHub Desktop.
Save tateisu/0cd25643e0ef3621f3535002268dbc8b to your computer and use it in GitHub Desktop.
SELECT "statuses"."id", "statuses"."updated_at" FROM "statuses"
LEFT OUTER JOIN mentions ON statuses.id = mentions.status_id AND mentions.account_id = 1867
WHERE "statuses"."account_id" = 1 AND ("statuses"."visibility" IN (0, 1, 2) OR "mentions"."id" IS NOT NULL)
ORDER BY "statuses"."id" DESC LIMIT 40;
Limit (cost=5.32..230.35 rows=40 width=16) (actual time=0.747..2.045 rows=40 loops=1)
-> Nested Loop Left Join (cost=5.32..2446.91 rows=434 width=16) (actual time=0.745..2.007 rows=40 loops=1)
Join Filter: (statuses.id = mentions.status_id)
Rows Removed by Join Filter: 920
Filter: ((statuses.visibility = ANY ('{0,1,2}'::integer[])) OR (mentions.id IS NOT NULL))
-> Index Scan Backward using index_statuses_on_account_id_id on statuses (cost=0.43..1732.20 rows=434 width=20) (actual time=0.043..0.272 rows=40 loops=1)
Index Cond: (account_id = 1)
-> Materialize (cost=4.89..226.61 rows=60 width=16) (actual time=0.002..0.028 rows=23 loops=40)
-> Bitmap Heap Scan on mentions (cost=4.89..226.31 rows=60 width=16) (actual time=0.055..0.645 rows=23 loops=1)
Recheck Cond: (account_id = 1867)
Heap Blocks: exact=20
-> Bitmap Index Scan on index_mentions_on_account_id_and_status_id (cost=0.00..4.88 rows=60 width=0) (actual time=0.036..0.036 rows=23 loops=1)
Index Cond: (account_id = 1867)
Planning time: 0.787 ms
Execution time: 2.120 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment