4s query want to run faster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

The following query takes about 4s to run in a 16GB ram server. Any ideas why it doesn´t use index for the primary keys in the join conditions?

select i.inuid, count(*) as total
from cte.instrumentounidade i
inner join cte.pontuacao p on p.inuid = i.inuid
inner join cte.acaoindicador ai on ai.ptoid = p.ptoid
inner join cte.subacaoindicador si on si.aciid = ai.aciid
where i.itrid = 2 and p.ptostatus = 'A'
group by i.inuid
having count(*) > 0

HashAggregate  (cost=47905.87..47941.01 rows=2008 width=4)
 Filter: (count(*) > 0)
 ->  Hash Join  (cost=16307.79..46511.45 rows=185923 width=4)
       Hash Cond: (si.aciid = ai.aciid)
       ->  Seq Scan on subacaoindicador si  (cost=0.00..22812.17 rows=368817 width=4)
       ->  Hash  (cost=16211.40..16211.40 rows=38556 width=8)
             ->  Hash Join  (cost=9018.20..16211.40 rows=38556 width=8)
                   Hash Cond: (p.inuid = i.inuid)
                   ->  Hash Join  (cost=8908.41..15419.10 rows=39593 width=8)
                         Hash Cond: (ai.ptoid = p.ptoid)
                         ->  Seq Scan on acaoindicador ai  (cost=0.00..4200.84 rows=76484 width=8)
                         ->  Hash  (cost=8678.33..8678.33 rows=92034 width=8)
                               ->  Seq Scan on pontuacao p  (cost=0.00..8678.33 rows=92034 width=8)
                                     Filter: (ptostatus = 'A'::bpchar)
                   ->  Hash  (cost=104.78..104.78 rows=2008 width=4)
                         ->  Seq Scan on instrumentounidade i  (cost=0.00..104.78 rows=2008 width=4)
                               Filter: (itrid = 2)
 

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux