explain.depesz.com

PostgreSQL's explain analyze made readable

Result: oCWu

Settings
# exclusive inclusive rows x rows loops node
1. 0.017 1,211.084 ↑ 1.0 25 1

Limit (cost=116,596.46..116,596.52 rows=25 width=140) (actual time=1,211.062..1,211.084 rows=25 loops=1)

2.          

CTE personal_prefs

3. 0.000 0.000 ↓ 0.0 0

Nested Loop Left Join (cost=0.84..23.12 rows=1 width=4) (never executed)

  • Filter: (COALESCE(useremailprefs_1.preference, defaultemailprefs_1.preference) = 1)
4. 0.000 0.000 ↓ 0.0 0

Index Scan using ix_defaultemailprefs_orgid on defaultemailprefs defaultemailprefs_1 (cost=0.42..14.67 rows=1 width=8) (never executed)

  • Index Cond: (orgid IS NULL)
  • Filter: (action = ANY ('{3,17,74}'::integer[]))
5. 0.000 0.000 ↓ 0.0 0

Index Scan using useremailprefs_userid_action_unique on useremailprefs useremailprefs_1 (cost=0.42..8.44 rows=1 width=8) (never executed)

  • Index Cond: ((userid = 1582576830) AND (action = defaultemailprefs_1.action))
6.          

CTE prefs

7. 44.287 1,134.815 ↓ 1,437.3 30,184 1

Merge Left Join (cost=6,267.77..19,951.23 rows=21 width=8) (actual time=125.635..1,134.815 rows=30,184 loops=1)

  • Merge Cond: (defaultemailprefs_2.action = defaultemailprefs_3.action)
  • Join Filter: (defaultemailprefs_3.groupid = invites.ownerid)
  • Rows Removed by Join Filter: 73502
  • Filter: (COALESCE(CASE WHEN ((defaultemailprefs_2.action = ANY ('{3,17,74,70,71}'::integer[])) OR (useremailprefs_3.preference = 4)) THEN COALESCE(useremailprefs_2.preference, defaultemailprefs_2.preference) ELSE useremailprefs_3.preference END, CASE WHEN (useremailprefs_5.preference = 4) THEN useremailprefs_4.preference ELSE useremailprefs_5.preference END, CASE WHEN (defaultemailprefs_4.preference = 4) THEN defaultemailprefs_3.preference ELSE defaultemailprefs_4.preference END, defaultemailprefs_2.preference) = 1)
  • Rows Removed by Filter: 24
8. 13.554 1,067.833 ↓ 7.3 30,208 1

Merge Left Join (cost=6,267.35..13,418.18 rows=4,110 width=32) (actual time=125.607..1,067.833 rows=30,208 loops=1)

  • Merge Cond: (defaultemailprefs_2.action = useremailprefs_4.action)
  • Join Filter: (useremailprefs_4.groupid = invites.ownerid)
9. 27.772 1,054.247 ↓ 7.3 30,208 1

Nested Loop Left Join (cost=6,235.83..13,376.34 rows=4,110 width=28) (actual time=125.572..1,054.247 rows=30,208 loops=1)

10. 13.575 1,026.475 ↓ 7.3 30,208 1

Nested Loop (cost=6,235.54..13,316.65 rows=4,110 width=24) (actual time=125.553..1,026.475 rows=30,208 loops=1)

11. 0.040 0.161 ↓ 7.0 7 1

Nested Loop Left Join (cost=0.84..17.19 rows=1 width=12) (actual time=0.013..0.161 rows=7 loops=1)

12. 0.023 0.023 ↓ 7.0 7 1

Index Scan using ix_defaultemailprefs_action on defaultemailprefs defaultemailprefs_2 (cost=0.42..8.73 rows=1 width=8) (actual time=0.004..0.023 rows=7 loops=1)

  • Index Cond: (action IS NOT NULL)
  • Filter: ((groupid IS NULL) AND (orgid IS NULL))
  • Rows Removed by Filter: 10
13. 0.098 0.098 ↓ 0.0 0 7

Index Scan using useremailprefs_userid_action_groupidnull_unique on useremailprefs useremailprefs_2 (cost=0.42..8.44 rows=1 width=8) (actual time=0.014..0.014 rows=0 loops=7)

  • Index Cond: ((userid = 1582576830) AND (action = defaultemailprefs_2.action))
14. 108.731 1,012.739 ↓ 1.0 4,315 7

Hash Left Join (cost=6,234.69..13,258.36 rows=4,110 width=12) (actual time=122.765..144.677 rows=4,315 loops=7)

  • Hash Cond: (invites.ownerid = defaultemailprefs_4.groupid)
15. 15.624 50.932 ↓ 1.1 4,362 7

Hash Left Join (cost=101.21..6,324.37 rows=4,110 width=8) (actual time=0.650..7.276 rows=4,362 loops=7)

  • Hash Cond: (invites.ownerid = useremailprefs_5.groupid)
16. 32.354 35.294 ↓ 1.1 4,362 7

Bitmap Heap Scan on invites (cost=88.89..6,291.28 rows=4,110 width=4) (actual time=0.646..5.042 rows=4,362 loops=7)

  • Recheck Cond: (userid = 1582576830)
  • Filter: (status = 1)
  • Rows Removed by Filter: 5
  • Heap Blocks: exact=12943
17. 2.940 2.940 ↑ 1.1 4,367 7

Bitmap Index Scan on ix_invites_userid (cost=0.00..87.86 rows=4,725 width=0) (actual time=0.420..0.420 rows=4,367 loops=7)

  • Index Cond: (userid = 1582576830)
18. 0.002 0.014 ↑ 2.0 1 1

Hash (cost=12.29..12.29 rows=2 width=8) (actual time=0.014..0.014 rows=1 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
19. 0.004 0.012 ↑ 2.0 1 1

Bitmap Heap Scan on useremailprefs useremailprefs_5 (cost=4.44..12.29 rows=2 width=8) (actual time=0.010..0.012 rows=1 loops=1)

  • Recheck Cond: ((userid = 1582576830) AND (action IS NULL))
  • Heap Blocks: exact=1
20. 0.008 0.008 ↑ 2.0 1 1

Bitmap Index Scan on useremailprefs_userid_action_unique (cost=0.00..4.44 rows=2 width=0) (actual time=0.007..0.008 rows=1 loops=1)

  • Index Cond: ((userid = 1582576830) AND (action IS NULL))
21. 427.378 853.076 ↑ 1.0 181,627 7

Hash (cost=3,152.76..3,152.76 rows=181,658 width=8) (actual time=121.868..121.868 rows=181,627 loops=7)

  • Buckets: 131072 Batches: 4 Memory Usage: 2809kB
22. 425.698 425.698 ↑ 1.0 181,639 7

Seq Scan on defaultemailprefs defaultemailprefs_4 (cost=0.00..3,152.76 rows=181,658 width=8) (actual time=0.007..60.814 rows=181,639 loops=7)

  • Filter: (action IS NULL)
  • Rows Removed by Filter: 37
23. 0.000 0.000 ↓ 0.0 0 30,208

Materialize (cost=0.29..8.31 rows=1 width=4) (actual time=0.000..0.000 rows=0 loops=30,208)

24. 0.013 0.013 ↓ 0.0 0 1

Index Scan using useremailprefs_userid_actionnull_groupidnull_unique on useremailprefs useremailprefs_3 (cost=0.29..8.31 rows=1 width=4) (actual time=0.013..0.013 rows=0 loops=1)

  • Index Cond: (userid = 1582576830)
25. 0.019 0.032 ↑ 7.0 1 1

Sort (cost=31.52..31.53 rows=7 width=12) (actual time=0.032..0.032 rows=1 loops=1)

  • Sort Key: useremailprefs_4.action
  • Sort Method: quicksort Memory: 25kB
26. 0.005 0.013 ↑ 7.0 1 1

Bitmap Heap Scan on useremailprefs useremailprefs_4 (cost=4.48..31.42 rows=7 width=12) (actual time=0.012..0.013 rows=1 loops=1)

  • Recheck Cond: (userid = 1582576830)
  • Heap Blocks: exact=1
27. 0.008 0.008 ↑ 7.0 1 1

Bitmap Index Scan on ix_useremailprefs_userid (cost=0.00..4.48 rows=7 width=0) (actual time=0.008..0.008 rows=1 loops=1)

  • Index Cond: (userid = 1582576830)
28. 22.695 22.695 ↑ 2.5 73,503 1

Index Scan using ix_defaultemailprefs_action on defaultemailprefs defaultemailprefs_3 (cost=0.42..6,068.56 rows=181,676 width=12) (actual time=0.012..22.695 rows=73,503 loops=1)

29. 0.040 1,211.067 ↑ 2.1 25 1

Sort (cost=96,622.11..96,622.24 rows=52 width=140) (actual time=1,211.060..1,211.067 rows=25 loops=1)

  • Sort Key: activity.created DESC
  • Sort Method: quicksort Memory: 28kB
30. 0.215 1,211.027 ↑ 2.1 25 1

Nested Loop Left Join (cost=197.75..96,620.64 rows=52 width=140) (actual time=1,144.843..1,211.027 rows=25 loops=1)

  • Filter: (((activity.action = ANY ('{3,17,74}'::integer[])) AND (hashed SubPlan 3)) OR ((activity.action <> ALL ('{3,17,74}'::integer[])) AND (SubPlan 6)))
31. 0.100 5.412 ↑ 4.2 25 1

Nested Loop (cost=197.43..95,637.40 rows=105 width=140) (actual time=5.152..5.412 rows=25 loops=1)

32. 3.922 4.807 ↑ 76.7 101 1

Bitmap Heap Scan on notification_recipients (cost=197.00..33,517.08 rows=7,744 width=28) (actual time=1.469..4.807 rows=101 loops=1)

  • Recheck Cond: (userid = 1582576830)
  • Filter: ((status <> 1) AND (email <> 1))
  • Rows Removed by Filter: 7433
  • Heap Blocks: exact=1644
33. 0.885 0.885 ↓ 1.1 11,890 1

Bitmap Index Scan on ix_notification_recipients_userid (cost=0.00..195.06 rows=10,483 width=0) (actual time=0.884..0.885 rows=11,890 loops=1)

  • Index Cond: (userid = 1582576830)
34. 0.505 0.505 ↓ 0.0 0 101

Index Scan using activity_pkey on activity (cost=0.43..8.01 rows=1 width=112) (actual time=0.005..0.005 rows=0 loops=101)

  • Index Cond: (id = notification_recipients.activityid)
  • Filter: ((created > '2019-06-02 23:14:35.699703'::timestamp without time zone) AND (delete_status = 0))
  • Rows Removed by Filter: 1
35. 0.000 0.000 ↓ 0.0 0 25

Index Scan using mentionkeys_pkey on mentionkeys (cost=0.29..0.65 rows=1 width=8) (actual time=0.000..0.000 rows=0 loops=25)

  • Index Cond: (id = notification_recipients.mentionid)
36.          

SubPlan (forNested Loop Left Join)

37. 0.000 0.000 ↓ 0.0 0

CTE Scan on personal_prefs (cost=0.00..0.02 rows=1 width=4) (never executed)

38. 0.000 0.000 ↓ 0.0 0

Index Scan using useremailprefs_userid_action_unique on useremailprefs (cost=0.42..8.44 rows=1 width=0) (never executed)

  • Index Cond: ((userid = 1582576830) AND (action = mentionkeys.action))
  • Filter: (preference IS NULL)
39. 0.000 0.000 ↓ 0.0 0

Bitmap Heap Scan on useremailprefs useremailprefs_6 (cost=4.48..31.42 rows=1 width=4) (never executed)

  • Recheck Cond: (userid = 1582576830)
  • Filter: (preference IS NULL)
40. 0.000 0.000 ↓ 0.0 0

Bitmap Index Scan on ix_useremailprefs_userid (cost=0.00..4.48 rows=7 width=0) (never executed)

  • Index Cond: (userid = 1582576830)
41. 1,205.400 1,205.400 ↓ 6.0 6 25

CTE Scan on prefs (cost=0.00..0.47 rows=1 width=4) (actual time=6.981..48.216 rows=6 loops=25)

  • Filter: (ownerid = notification_recipients.ctxid)
  • Rows Removed by Filter: 25675
Planning time : 2.660 ms
Execution time : 1,211.557 ms