cityvox_prod=# set enable_nestloop = off; SET cityvox_prod=# EXPLAIN ANALYZE SELECT a.numasso, a.nomasso, a.nomassoofficiel, el.numeve, el.numlieu, vq.codequar, toTimestamp(ddebevelieu) as debutevelieu, toTimestamp(dfinevelieu) as finevelieu FROM association a, evelieu el, assovil av, lieu l, vilquartier vq WHERE 1=1 AND l.codequar = vq.codequar AND l.numlieu = el.numlieu AND vq.codevil = av.codevil AND a.numasso = el.numasso AND a.numasso = av.numasso AND a.codeact = 'V' AND av.codevil = 'LYO' AND date_trunc('day', el.dfinevelieu) >= date_trunc('day', now()) ORDER BY el.numeve ASC LIMIT 5; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=11724.96..11724.97 rows=1 width=68) (actual time=209.723..209.726 rows=1 loops=1) -> Sort (cost=11724.96..11724.97 rows=1 width=68) (actual time=209.721..209.722 rows=1 loops=1) Sort Key: el.numeve Sort Method: quicksort Memory: 25kB -> Hash Join (cost=4760.99..11724.95 rows=1 width=68) (actual time=182.555..209.699 rows=1 loops=1) Hash Cond: ((l.codequar)::text = (vq.codequar)::text) -> Hash Join (cost=4740.63..11704.47 rows=4 width=72) (actual time=71.275..209.553 rows=2 loops=1) Hash Cond: (l.numlieu = el.numlieu) -> Seq Scan on lieu l (cost=0.00..6481.40 rows=128640 width=9) (actual time=0.006..85.340 rows=128640 loops=1) -> Hash (cost=4740.58..4740.58 rows=4 width=67) (actual time=45.302..45.302 rows=2 loops=1) -> Hash Join (cost=835.85..4740.58 rows=4 width=67) (actual time=20.648..45.296 rows=2 loops=1) Hash Cond: (el.numasso = a.numasso) -> Bitmap Heap Scan on evelieu el (cost=759.63..4449.79 rows=57208 width=28) (actual time=8.854..27.657 rows=28019 loops=1) Recheck Cond: (date_trunc('day'::text, dfinevelieu) >= date_trunc('day'::text, now())) -> Bitmap Index Scan on idx_evelieu_dfinevelieu_trunc (cost=0.00..745.33 rows=57208 width=0) (actual time=8.707..8.707 rows=28019 loops=1) Index Cond: (date_trunc('day'::text, dfinevelieu) >= date_trunc('day'::text, now())) -> Hash (cost=75.84..75.84 rows=30 width=47) (actual time=1.808..1.808 rows=26 loops=1) -> Hash Join (cost=49.16..75.84 rows=30 width=47) (actual time=1.546..1.783 rows=26 loops=1) Hash Cond: (av.numasso = a.numasso) -> Seq Scan on assovil av (cost=0.00..26.24 rows=38 width=8) (actual time=0.015..0.205 rows=38 loops=1) Filter: ((codevil)::text = 'LYO'::text) -> Hash (cost=40.20..40.20 rows=717 width=39) (actual time=1.519..1.519 rows=717 loops=1) -> Seq Scan on association a (cost=0.00..40.20 rows=717 width=39) (actual time=0.005..0.886 rows=717 loops=1) Filter: ((codeact)::text = 'V'::text) -> Hash (cost=20.14..20.14 rows=18 width=9) (actual time=0.088..0.088 rows=18 loops=1) -> Bitmap Heap Scan on vilquartier vq (cost=2.39..20.14 rows=18 width=9) (actual time=0.043..0.063 rows=18 loops=1) Recheck Cond: ((codevil)::text = 'LYO'::text) -> Bitmap Index Scan on idx_vilquartier_codevil (cost=0.00..2.39 rows=18 width=0) (actual time=0.035..0.035 rows=18 loops=1) Index Cond: ((codevil)::text = 'LYO'::text) Total runtime: 209.839 ms