explain.depesz.com

PostgreSQL's explain analyze made readable

Result: ycch

Settings
# exclusive inclusive rows x rows loops node
1. 0.020 10,257.491 ↑ 1.0 25 1

Limit (cost=137,349.81..137,349.87 rows=25 width=140) (actual time=10,257.466..10,257.491 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. 43.939 1,150.366 ↓ 1,452.9 30,510 1

Merge Left Join (cost=6,267.77..19,951.23 rows=21 width=8) (actual time=131.201..1,150.366 rows=30,510 loops=1)

  • Merge Cond: (defaultemailprefs_2.action = defaultemailprefs_3.action)
  • Join Filter: (defaultemailprefs_3.groupid = invites.ownerid)
  • Rows Removed by Join Filter: 74154
  • 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. 14.118 1,084.101 ↓ 7.4 30,534 1

Merge Left Join (cost=6,267.35..13,418.18 rows=4,110 width=32) (actual time=131.170..1,084.101 rows=30,534 loops=1)

  • Merge Cond: (defaultemailprefs_2.action = useremailprefs_4.action)
  • Join Filter: (useremailprefs_4.groupid = invites.ownerid)
9. 26.617 1,069.949 ↓ 7.4 30,534 1

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

10. 13.220 1,043.332 ↓ 7.4 30,534 1

Nested Loop (cost=6,235.54..13,316.65 rows=4,110 width=24) (actual time=131.113..1,043.332 rows=30,534 loops=1)

11. 0.039 0.167 ↓ 7.0 7 1

Nested Loop Left Join (cost=0.84..17.19 rows=1 width=12) (actual time=0.014..0.167 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.105 0.105 ↓ 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.015..0.015 rows=0 loops=7)

  • Index Cond: ((userid = 1582576830) AND (action = defaultemailprefs_2.action))
14. 105.532 1,029.945 ↓ 1.1 4,362 7

Hash Left Join (cost=6,234.69..13,258.36 rows=4,110 width=12) (actual time=126.069..147.135 rows=4,362 loops=7)

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

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

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

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

  • Recheck Cond: (userid = 1582576830)
  • Filter: (status = 1)
  • Rows Removed by Filter: 5
  • Heap Blocks: exact=12943
17. 2.961 2.961 ↑ 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.423..0.423 rows=4,367 loops=7)

  • Index Cond: (userid = 1582576830)
18. 0.005 0.017 ↑ 2.0 1 1

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

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
19. 0.002 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.012..0.012 rows=1 loops=1)

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

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

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

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

  • Buckets: 131072 Batches: 4 Memory Usage: 2809kB
22. 427.406 427.406 ↑ 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.008..61.058 rows=181,639 loops=7)

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

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

24. 0.012 0.012 ↓ 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.012..0.012 rows=0 loops=1)

  • Index Cond: (userid = 1582576830)
25. 0.022 0.034 ↑ 7.0 1 1

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

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

Bitmap Heap Scan on useremailprefs useremailprefs_4 (cost=4.48..31.42 rows=7 width=12) (actual time=0.011..0.012 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.326 22.326 ↑ 2.4 74,155 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.013..22.326 rows=74,155 loops=1)

29. 3.791 10,257.471 ↑ 2.8 25 1

Sort (cost=117,375.46..117,375.64 rows=71 width=140) (actual time=10,257.465..10,257.471 rows=25 loops=1)

  • Sort Key: activity.created DESC
  • Sort Method: top-N heapsort Memory: 28kB
30. 20.693 10,253.680 ↓ 61.2 4,344 1

Nested Loop Left Join (cost=198.42..117,373.46 rows=71 width=140) (actual time=1,142.623..10,253.680 rows=4,344 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. 7.358 46.307 ↓ 30.6 4,344 1

Nested Loop (cost=198.10..116,056.50 rows=142 width=140) (actual time=0.914..46.307 rows=4,344 loops=1)

32. 8.128 8.813 ↑ 1.4 7,534 1

Bitmap Heap Scan on notification_recipients (cost=197.67..33,485.10 rows=10,480 width=28) (actual time=0.895..8.813 rows=7,534 loops=1)

  • Recheck Cond: (userid = 1582576830)
  • Filter: (status <> 1)
  • Heap Blocks: exact=1615
33. 0.685 0.685 ↑ 1.4 7,534 1

Bitmap Index Scan on ix_notification_recipients_userid (cost=0.00..195.05 rows=10,481 width=0) (actual time=0.685..0.685 rows=7,534 loops=1)

  • Index Cond: (userid = 1582576830)
34. 30.136 30.136 ↑ 1.0 1 7,534

Index Scan using activity_pkey on activity (cost=0.43..7.87 rows=1 width=112) (actual time=0.004..0.004 rows=1 loops=7,534)

  • 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: 0
35. 4.344 4.344 ↓ 0.0 0 4,344

Index Scan using mentionkeys_pkey on mentionkeys (cost=0.29..0.56 rows=1 width=8) (actual time=0.001..0.001 rows=0 loops=4,344)

  • 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. 10,182.336 10,182.336 ↓ 6.0 6 4,344

CTE Scan on prefs (cost=0.00..0.47 rows=1 width=4) (actual time=0.213..2.344 rows=6 loops=4,344)

  • Filter: (ownerid = notification_recipients.ctxid)
  • Rows Removed by Filter: 25814
Planning time : 2.689 ms
Execution time : 10,258.283 ms