execution time ~ 12-13 mins. NOTICE: QUERY PLAN: Subquery Scan progress_report (cost=14687.00..14687.00 rows=2 width=128) -> Sort (cost=14687.00..14687.00 rows=2 width=128) -> Nested Loop (cost=14605.17..14686.99 rows=2 width=128) -> Seq Scan on activity (cost=0.00..11.00 rows=1 width=48) -> Subquery Scan media_acts (cost=14605.17..14671.27 rows=378 width=112) -> Aggregate (cost=14605.17..14671.27 rows=378 width=112) -> Group (cost=14605.17..14614.61 rows=3777 width=112) -> Sort (cost=14605.17..14605.17 rows=3777 width=112) -> Subquery Scan stats (cost=14003.05..14380.75 rows=3777 width=112) -> Unique (cost=14003.05..14380.75 rows=3777 width=112) -> Sort (cost=14003.05..14003.05 rows=37771 width=112) -> Append (cost=1.31..9627.85 rows=37771 width=112) -> Subquery Scan *SELECT* 1 (cost=1.31..1154.05 rows=11459 width=56) -> Hash Join (cost=1.31..1154.05 rows=11459 width=56) -> Seq Scan on media (cost=0.00..407.59 rows=11459 width=36) -> Hash (cost=1.25..1.25 rows=25 width=20) -> Seq Scan on mediatypemap (cost=0.00..1.25 rows=25 width=20) -> Subquery Scan *SELECT* 2 (cost=1313.31..4930.60 rows=21196 width=80) -> Hash Join (cost=1313.31..4930.60 rows=21196 width=80) -> Hash Join (cost=1283.70..3513.64 rows=21196 width=64) -> Seq Scan on intsetmedia (cost=0.00..399.96 rows=21196 width=16) -> Hash (cost=1154.05..1154.05 rows=11459 width=48) -> Hash Join (cost=1.31..1154.05 rows=11459 width=48) -> Seq Scan on media (cost=0.00..407.59 rows=11459 width=28) -> Hash (cost=1.25..1.25 rows=25 width=20) -> Seq Scan on mediatypemap (cost=0.00..1.25 rows=25 width=20) -> Hash (cost=27.69..27.69 rows=769 width=16) -> Seq Scan on set (cost=0.00..27.69 rows=769 width=16) -> Subquery Scan *SELECT* 3 (cost=1993.99..3543.20 rows=5116 width=112) -> Hash Join (cost=1993.99..3543.20 rows=5116 width=112) -> Hash Join (cost=1992.68..3209.05 rows=5116 width=92) -> Seq Scan on media (cost=0.00..407.59 rows=11459 width=28) -> Hash (cost=1979.89..1979.89 rows=5116 width=64) -> Hash Join (cost=690.05..1979.89 rows=5116 width=64) -> Hash Join (cost=585.40..1498.78 rows=9148 width=32) -> Seq Scan on dtrowmedia (cost=0.00..164.48 rows=9148 width=16) -> Hash (cost=306.99..306.99 rows=16799 width=16) -> Seq Scan on dtrow (cost=0.00..306.99 rows=16799 width=16) -> Hash (cost=102.55..102.55 rows=842 width=32) -> Hash Join (cost=6.62..102.55 rows=842 width=32) -> Seq Scan on dtcol (cost=0.00..32.06 rows=1506 width=16) -> Hash (cost=5.90..5.90 rows=290 width=16) -> Seq Scan on datatable (cost=0.00..5.90 rows=290 width=16) -> Hash (cost=1.25..1.25 rows=25 width=20) -> Seq Scan on mediatypemap (cost=0.00..1.25 rows=25 width=20) EXPLAIN