explain.depesz.com

PostgreSQL's explain analyze made readable

Result: wDKkq

Settings
# exclusive inclusive rows x rows loops node
1. 0.012 8.769 ↓ 8.3 25 1

Limit (cost=7,016.09..7,016.12 rows=3 width=158) (actual time=8.626..8.769 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 = 943004921) AND (action = defaultemailprefs_1.action))
6.          

CTE prefs

7. 0.131 1.517 ↓ 88.0 88 1

Nested Loop Left Join (cost=15.36..161.70 rows=1 width=8) (actual time=0.132..1.517 rows=88 loops=1)

  • 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: 22
8. 0.139 1.166 ↓ 27.5 110 1

Nested Loop Left Join (cost=14.94..127.85 rows=4 width=32) (actual time=0.125..1.166 rows=110 loops=1)

  • Join Filter: (defaultemailprefs_3.action = defaultemailprefs_2.action)
  • Rows Removed by Join Filter: 110
9. 0.097 0.807 ↓ 27.5 110 1

Nested Loop Left Join (cost=14.52..94.05 rows=4 width=28) (actual time=0.115..0.807 rows=110 loops=1)

  • Join Filter: (useremailprefs_5.groupid = invites.ownerid)
10. 0.160 0.710 ↓ 27.5 110 1

Nested Loop Left Join (cost=10.07..81.63 rows=4 width=24) (actual time=0.105..0.710 rows=110 loops=1)

  • Join Filter: ((useremailprefs_4.groupid = invites.ownerid) AND (useremailprefs_4.action = defaultemailprefs_2.action))
  • Rows Removed by Join Filter: 220
11. 0.102 0.440 ↓ 27.5 110 1

Nested Loop Left Join (cost=5.60..49.70 rows=4 width=20) (actual time=0.034..0.440 rows=110 loops=1)

12. 0.081 0.338 ↓ 27.5 110 1

Nested Loop (cost=5.31..41.34 rows=4 width=16) (actual time=0.027..0.338 rows=110 loops=1)

13. 0.019 0.081 ↓ 22.0 22 1

Nested Loop Left Join (cost=0.84..17.19 rows=1 width=12) (actual time=0.011..0.081 rows=22 loops=1)

14. 0.018 0.018 ↓ 22.0 22 1

Index Scan using ix_defaultemailprefs_action on defaultemailprefs defaultemailprefs_2 (cost=0.42..8.73 rows=1 width=8) (actual time=0.003..0.018 rows=22 loops=1)

  • Index Cond: (action IS NOT NULL)
  • Filter: ((groupid IS NULL) AND (orgid IS NULL))
  • Rows Removed by Filter: 15
15. 0.044 0.044 ↓ 0.0 0 22

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

  • Index Cond: ((userid = 943004921) AND (action = defaultemailprefs_2.action))
16. 0.110 0.176 ↓ 1.2 5 22

Bitmap Heap Scan on invites (cost=4.46..24.12 rows=4 width=4) (actual time=0.004..0.008 rows=5 loops=22)

  • Recheck Cond: (userid = 943004921)
  • Filter: (status = 1)
  • Heap Blocks: exact=110
17. 0.066 0.066 ↑ 1.0 5 22

Bitmap Index Scan on ix_invites_userid (cost=0.00..4.46 rows=5 width=0) (actual time=0.003..0.003 rows=5 loops=22)

  • Index Cond: (userid = 943004921)
18. 0.000 0.000 ↓ 0.0 0 110

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

19. 0.004 0.004 ↓ 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.004..0.004 rows=0 loops=1)

  • Index Cond: (userid = 943004921)
20. 0.046 0.110 ↑ 3.5 2 110

Materialize (cost=4.48..31.45 rows=7 width=12) (actual time=0.000..0.001 rows=2 loops=110)

21. 0.056 0.064 ↑ 3.5 2 1

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

  • Recheck Cond: (userid = 943004921)
  • Heap Blocks: exact=2
22. 0.008 0.008 ↑ 3.5 2 1

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

  • Index Cond: (userid = 943004921)
23. 0.000 0.000 ↓ 0.0 0 110

Materialize (cost=4.44..12.30 rows=2 width=8) (actual time=0.000..0.000 rows=0 loops=110)

24. 0.003 0.010 ↓ 0.0 0 1

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

  • Recheck Cond: ((userid = 943004921) AND (action IS NULL))
25. 0.007 0.007 ↓ 0.0 0 1

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

  • Index Cond: ((userid = 943004921) AND (action IS NULL))
26. 0.220 0.220 ↑ 1.0 1 110

Index Scan using ix_defaultemailprefs_groupid on defaultemailprefs defaultemailprefs_3 (cost=0.42..8.44 rows=1 width=12) (actual time=0.002..0.002 rows=1 loops=110)

  • Index Cond: (groupid = invites.ownerid)
27. 0.220 0.220 ↑ 1.0 1 110

Index Scan using ix_defaultemailprefs_groupid on defaultemailprefs defaultemailprefs_4 (cost=0.42..8.44 rows=1 width=8) (actual time=0.001..0.002 rows=1 loops=110)

  • Index Cond: (groupid = invites.ownerid)
  • Filter: (action IS NULL)
28. 0.146 8.757 ↓ 8.3 25 1

LockRows (cost=6,831.26..6,831.30 rows=3 width=158) (actual time=8.625..8.757 rows=25 loops=1)

29. 0.057 8.611 ↓ 8.3 25 1

Sort (cost=6,831.26..6,831.27 rows=3 width=158) (actual time=8.604..8.611 rows=25 loops=1)

  • Sort Key: activity.created DESC
  • Sort Method: quicksort Memory: 34kB
30. 0.737 8.554 ↓ 23.0 69 1

Nested Loop Left Join (cost=13.44..6,831.24 rows=3 width=158) (actual time=2.538..8.554 rows=69 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)))
  • Rows Removed by Filter: 227
31. 0.217 3.961 ↓ 49.3 296 1

Nested Loop (cost=13.13..6,755.15 rows=6 width=152) (actual time=0.218..3.961 rows=296 loops=1)

32. 1.035 1.120 ↓ 1.2 656 1

Bitmap Heap Scan on notification_recipients (cost=12.69..2,122.49 rows=549 width=34) (actual time=0.156..1.120 rows=656 loops=1)

  • Recheck Cond: (userid = 943004921)
  • Filter: (status <> 1)
  • Heap Blocks: exact=601
33. 0.085 0.085 ↓ 1.2 658 1

Bitmap Index Scan on ix_notification_recipients_userid (cost=0.00..12.55 rows=549 width=0) (actual time=0.085..0.085 rows=658 loops=1)

  • Index Cond: (userid = 943004921)
34. 2.624 2.624 ↓ 0.0 0 656

Index Scan using activity_pkey on activity (cost=0.43..8.43 rows=1 width=118) (actual time=0.003..0.004 rows=0 loops=656)

  • Index Cond: (id = notification_recipients.activityid)
  • Filter: ((created > '2019-06-05 07:16:51.934167'::timestamp without time zone) AND (delete_status = 0))
  • Rows Removed by Filter: 1
35. 0.000 0.000 ↓ 0.0 0 296

Index Scan using mentionkeys_pkey on mentionkeys (cost=0.29..4.19 rows=1 width=14) (actual time=0.000..0.000 rows=0 loops=296)

  • 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.008 0.008 ↑ 1.0 1 4

Index Scan using useremailprefs_userid_action_unique on useremailprefs (cost=0.42..8.44 rows=1 width=0) (actual time=0.002..0.002 rows=1 loops=4)

  • Index Cond: ((userid = 943004921) 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 = 943004921)
  • 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 = 943004921)
41. 3.848 3.848 ↓ 4.0 4 296

CTE Scan on prefs (cost=0.00..0.02 rows=1 width=4) (actual time=0.005..0.013 rows=4 loops=296)

  • Filter: (ownerid = notification_recipients.ctxid)
  • Rows Removed by Filter: 68