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=3964.90..3964.91 rows=1 width=77) (actual time=305.762..305.775 rows=1 loops=1) -> Sort (cost=3964.90..3964.91 rows=1 width=77) (actual time=305.752..305.757 rows=1 loops=1) Sort Key: el.numeve -> Nested Loop (cost=332.95..3964.89 rows=1 width=77) (actual time=128.550..305.711 rows=1 loops=1) -> Nested Loop (cost=332.95..3960.88 rows=1 width=84) (actual time=128.454..305.557 rows=2 loops=1) -> Nested Loop (cost=332.95..3956.85 rows=1 width=76) (actual time=128.409..305.443 rows=2 loops=1) -> Hash Join (cost=332.95..3953.41 rows=1 width=73) (actual time=88.687..303.937 rows=66 loops=1) Hash Cond: ("outer".numasso = "inner".numasso) -> Bitmap Heap Scan on evelieu el (cost=282.57..3757.93 rows=29018 width=28) (actual time=44.335..178.776 rows=28512 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..282.57 rows=29018 width=0) (actual time=43.811..43.811 rows=28512 loops=1) Index Cond: (date_trunc('day'::text, dfinevelieu) >= date_trunc('day'::text, now())) -> Hash (cost=48.54..48.54 rows=738 width=45) (actual time=9.575..9.575 rows=718 loops=1) -> Seq Scan on association a (cost=0.00..48.54 rows=738 width=45) (actual time=0.015..4.835 rows=718 loops=1) Filter: ((codeact)::text = 'V'::text) -> Index Scan using pk_assovil on assovil av (cost=0.00..3.43 rows=1 width=11) (actual time=0.014..0.014 rows=0 loops=66) Index Cond: (("outer".numasso = av.numasso) AND ((av.codevil)::text = 'LYO'::text)) -> Index Scan using pk_lieu on lieu l (cost=0.00..4.01 rows=1 width=12) (actual time=0.026..0.031 rows=1 loops=2) Index Cond: (l.numlieu = "outer".numlieu) -> Index Scan using pk_vilquartier on vilquartier vq (cost=0.00..3.99 rows=1 width=15) (actual time=0.032..0.035 rows=0 loops=2) Index Cond: ((("outer".codequar)::text = (vq.codequar)::text) AND ('LYO'::text = (vq.codevil)::text)) Total runtime: 306.182 ms (22 rows)