Original query:

"Subquery Scan on pn  (cost=199307.25..211420.78 rows=1731 width=23) (actual time=1170.275..1178.318 rows=4893 loops=1)"
"  Filter: (pn.numero_ligne = 1)"
"  Rows Removed by Filter: 12028"
"  ->  WindowAgg  (cost=199307.25..207094.52 rows=346101 width=47) (actual time=1170.274..1177.231 rows=16921 loops=1)"
"        ->  Sort  (cost=199307.25..200172.50 rows=346101 width=39) (actual time=1170.265..1171.220 rows=16921 loops=1)"
"              Sort Key: projets.sm001000_pi2_projet_infrastructureid, (COALESCE(sm001000_pi8_action_dossierbase.sm001000_pi_d_effc_even, '1900-01-01 00:00:00-05'::timestamp with time zone)) DESC, (COALESCE(sm001000_pi8_action_dossierbase.sm001000_pi_d_fin_actn, '1900-01-01 00:00:00-05'::timestamp with time zone)) DESC"
"              Sort Method: quicksort  Memory: 2090kB"
"              ->  Hash Join  (cost=123793.80..158000.51 rows=346101 width=39) (actual time=1018.859..1163.023 rows=16921 loops=1)"
"                    Hash Cond: (sm001000_pi8_action_dossierbase.sm001000_pi8_etape_dossierid = sm001000_pi8_etape_dossierbase.sm001000_pi8_etape_dossierid)"
"                    ->  Hash Join  (cost=34.88..17308.77 rows=86779 width=35) (actual time=0.100..112.148 rows=16921 loops=1)"
"                          Hash Cond: (sm001000_pi8_action_dossierbase.sm001000_pi9_nature_evenement_affaireid = sm001000_pi9_nature_evenement_affairebase.sm001000_pi9_nature_evenement_affaireid)"
"                          ->  Seq Scan on sm001000_pi8_action_dossierbase  (cost=0.00..14925.73 rows=66846 width=192) (actual time=0.008..80.108 rows=173935 loops=1)"
"                                Filter: (sm001000_pi_d_effc_even < '2019-01-02 00:00:00-05'::timestamp with time zone)"
"                                Rows Removed by Filter: 26427"
"                          ->  Hash  (cost=28.66..28.66 rows=498 width=35) (actual time=0.064..0.064 rows=21 loops=1)"
"                                Buckets: 1024  Batches: 1  Memory Usage: 10kB"
"                                ->  Hash Join  (cost=5.09..28.66 rows=498 width=35) (actual time=0.054..0.060 rows=21 loops=1)"
"                                      Hash Cond: (n_a_conserver.sm001000_pi9_nature_evenement_affaireid = sm001000_pi9_nature_evenement_affairebase.sm001000_pi9_nature_evenement_affaireid)"
"                                      ->  Seq Scan on natr_evnt_affr n_a_conserver  (cost=0.00..20.70 rows=1070 width=16) (actual time=0.003..0.005 rows=21 loops=1)"
"                                      ->  Hash  (cost=3.93..3.93 rows=93 width=67) (actual time=0.045..0.045 rows=93 loops=1)"
"                                            Buckets: 1024  Batches: 1  Memory Usage: 18kB"
"                                            ->  Seq Scan on sm001000_pi9_nature_evenement_affairebase  (cost=0.00..3.93 rows=93 width=67) (actual time=0.004..0.027 rows=93 loops=1)"
"                    ->  Hash  (cost=93950.58..93950.58 rows=1467467 width=36) (actual time=1018.541..1018.541 rows=208838 loops=1)"
"                          Buckets: 65536  Batches: 32  Memory Usage: 960kB"
"                          ->  Hash Join  (cost=37580.41..93950.58 rows=1467467 width=36) (actual time=743.443..971.383 rows=208838 loops=1)"
"                                Hash Cond: (projets.sm001000_pi2_projet_infrastructureid = sm001000_pi8_etape_dossierbase.sm001000_pi2_projet_infrastructureid)"
"                                ->  Seq Scan on projets_filtres projets  (cost=0.00..702.00 rows=44200 width=20) (actual time=0.006..5.510 rows=40734 loops=1)"
"                                ->  Hash  (cost=21125.85..21125.85 rows=367885 width=240) (actual time=742.956..742.956 rows=208937 loops=1)"
"                                      Buckets: 16384  Batches: 32  Memory Usage: 1302kB"
"                                      ->  Seq Scan on sm001000_pi8_etape_dossierbase  (cost=0.00..21125.85 rows=367885 width=240) (actual time=0.035..626.337 rows=367749 loops=1)"
"Planning time: 13.231 ms"
"Execution time: 1178.582 ms"