QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=710118.74..710118.75 rows=3 width=567) (actual time=51563.029..51580.020 rows=80963 loops=1) Sort Key: rec.startdatetime, rec.id Sort Method: quicksort Memory: 43163kB -> Hash Join (cost=360922.21..710118.72 rows=3 width=567) (actual time=43014.876..51132.786 rows=80963 loops=1) Hash Cond: ((rec.acsguid)::text = (resolve.resolve)::text) -> Merge Join (cost=360655.21..709851.67 rows=3 width=567) (actual time=42458.324..50434.884 rows=80963 loops=1) Merge Cond: (rec.startdatetime = (max(dummymediastatus.startdatetime))) Join Filter: ((rec.volumeguid)::text = (dummymediastatus.volumeguid)::text) -> Index Scan using index_dummymediastatus_startdatetime on dummymediastatus rec (cost=0.00..339020.12 rows=4000362 width=414) (actual time=41.617..6324.895 rows=3999952 loops=1) -> Sort (cost=360655.21..360664.23 rows=3608 width=153) (actual time=42416.687..42453.669 rows=81934 loops=1) Sort Key: (max(dummymediastatus.startdatetime)) Sort Method: quicksort Memory: 5174kB -> HashAggregate (cost=360360.86..360405.96 rows=3608 width=16) (actual time=42257.696..42309.261 rows=80000 loops=1) -> Hash Join (cost=335135.05..354817.67 rows=1108637 width=16) (actual time=37252.925..39518.267 rows=4000000 loops=1) Hash Cond: ((getcurrentguids.getcurrentguids)::text = (dummymediastatus.volumeguid)::text) -> Function Scan on getcurrentguids (cost=0.00..260.00 rows=1000 width=32) (actual time=530.526..551.294 rows=80000 loops=1) -> Hash (cost=285135.53..285135.53 rows=3999962 width=16) (actual time=36722.012..36722.012 rows=4000000 loops=1) -> Seq Scan on dummymediastatus (cost=0.00..285135.53 rows=3999962 width=16) (actual time=0.014..34178.595 rows=4000000 loops=1) Filter: (startdatetime <= 1249281281666::bigint) -> Hash (cost=264.50..264.50 rows=200 width=32) (actual time=556.523..556.523 rows=1 loops=1) -> HashAggregate (cost=262.50..264.50 rows=200 width=32) (actual time=556.518..556.519 rows=1 loops=1) -> Function Scan on resolve (cost=0.00..260.00 rows=1000 width=32) (actual time=556.510..556.510 rows=1 loops=1) Total runtime: 51713.047 ms