                                                                                                         QUERY PLAN                                                                                                          
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Finalize Aggregate  (cost=433938.40..433938.41 rows=1 width=8) (actual time=1324.805..1384.694 rows=1 loops=1)
   ->  Gather  (cost=433938.19..433938.40 rows=2 width=8) (actual time=1323.712..1384.690 rows=3 loops=1)
         Workers Planned: 2
         Workers Launched: 2
         ->  Partial Aggregate  (cost=432938.19..432938.20 rows=1 width=8) (actual time=1322.444..1322.455 rows=1 loops=3)
               ->  Parallel Hash Join  (cost=347888.29..430918.53 rows=807861 width=4) (actual time=1135.831..1287.886 rows=1523232 loops=3)
                     Hash Cond: (attachments.folder_id = folders.id)
                     ->  Parallel Seq Scan on attachments  (cost=0.00..54689.63 rows=1975074 width=8) (actual time=0.015..74.821 rows=1576685 loops=3)
                           Filter: (NOT is_deleted)
                           Rows Removed by Filter: 327767
                     ->  Parallel Hash  (cost=338919.45..338919.45 rows=546627 width=4) (actual time=988.970..988.979 rows=1030633 loops=3)
                           Buckets: 262144  Batches: 16  Memory Usage: 9664kB
                           ->  Parallel Hash Join  (cost=222930.79..338919.45 rows=546627 width=4) (actual time=862.438..942.550 rows=1030633 loops=3)
                                 Hash Cond: (folders.event_id = events.id)
                                 ->  Parallel Hash Left Join  (cost=199218.52..306522.55 rows=623482 width=8) (actual time=647.388..774.130 rows=1058109 loops=3)
                                       Hash Cond: (folders.contribution_id = contributions.id)
                                       Filter: (NOT COALESCE(sessions.is_deleted, contributions.is_deleted, subcontributions.is_deleted, false))
                                       Rows Removed by Filter: 6434
                                       ->  Parallel Hash Left Join  (cost=93909.23..175314.98 rows=1246964 width=14) (actual time=351.134..404.342 rows=1064544 loops=3)
                                             Hash Cond: (folders.session_id = sessions.id)
                                             ->  Parallel Hash Left Join  (cost=84126.27..146673.74 rows=1246964 width=17) (actual time=217.466..279.889 rows=1064544 loops=3)
                                                   Hash Cond: (folders.subcontribution_id = subcontributions.id)
                                                   Filter: ((contributions_1.is_deleted IS NULL) OR (NOT contributions_1.is_deleted))
                                                   Rows Removed by Filter: 157
                                                   ->  Parallel Seq Scan on folders  (cost=0.00..40289.07 rows=1331373 width=20) (actual time=0.016..59.322 rows=1064701 loops=3)
                                                         Filter: ((NOT is_deleted) AND (link_type <> 1))
                                                         Rows Removed by Filter: 4424
                                                   ->  Parallel Hash  (cost=78785.58..78785.58 rows=325495 width=6) (actual time=103.535..103.536 rows=184447 loops=3)
                                                         Buckets: 262144  Batches: 4  Memory Usage: 7488kB
                                                         ->  Nested Loop Left Join  (cost=0.44..78785.58 rows=325495 width=6) (actual time=0.030..90.520 rows=184447 loops=3)
                                                               ->  Parallel Seq Scan on subcontributions  (cost=0.00..6246.95 rows=325495 width=9) (actual time=0.002..6.298 rows=184447 loops=3)
                                                               ->  Memoize  (cost=0.44..0.84 rows=1 width=5) (actual time=0.000..0.000 rows=1 loops=553341)
                                                                     Cache Key: subcontributions.contribution_id
                                                                     Cache Mode: logical
                                                                     Hits: 135333  Misses: 47817  Evictions: 0  Overflows: 0  Memory Usage: 4904kB
                                                                     Worker 0:  Hits: 136389  Misses: 48426  Evictions: 0  Overflows: 0  Memory Usage: 4966kB
                                                                     Worker 1:  Hits: 137268  Misses: 48108  Evictions: 0  Overflows: 0  Memory Usage: 4933kB
                                                                     ->  Index Scan using pk_contributions on contributions contributions_1  (cost=0.43..0.83 rows=1 width=5) (actual time=0.001..0.001 rows=1 loops=144351)
                                                                           Index Cond: (id = subcontributions.contribution_id)
                                             ->  Parallel Hash  (cost=5706.98..5706.98 rows=248398 width=5) (actual time=17.667..17.667 rows=198719 loops=3)
                                                   Buckets: 262144  Batches: 4  Memory Usage: 7936kB
                                                   ->  Parallel Seq Scan on sessions  (cost=0.00..5706.98 rows=248398 width=5) (actual time=0.003..7.229 rows=198719 loops=3)
                                       ->  Parallel Hash  (cost=61434.91..61434.91 rows=2674191 width=5) (actual time=184.109..184.109 rows=2139359 loops=3)
                                             Buckets: 262144  Batches: 64  Memory Usage: 6048kB
                                             ->  Parallel Seq Scan on contributions  (cost=0.00..61434.91 rows=2674191 width=5) (actual time=0.009..83.995 rows=2139359 loops=3)
                                 ->  Parallel Hash  (cost=14575.53..14575.53 rows=556859 width=4) (actual time=38.855..38.855 rows=444370 loops=3)
                                       Buckets: 262144  Batches: 16  Memory Usage: 5344kB
                                       ->  Parallel Seq Scan on events  (cost=0.00..14575.53 rows=556859 width=4) (actual time=0.008..18.893 rows=444370 loops=3)
                                             Filter: (NOT is_deleted)
                                             Rows Removed by Filter: 63752
 Planning Time: 1.354 ms
 Execution Time: 1385.414 ms
(52 rows)
