execution time ~ 15sec. NOTICE: QUERY PLAN: Subquery Scan progress_report (cost=14648.65..14648.65 rows=4 width=128) -> Sort (cost=14648.65..14648.65 rows=4 width=128) -> Merge Join (cost=14644.00..14648.62 rows=4 width=128) -> Sort (cost=11.02..11.02 rows=2 width=48) -> Seq Scan on activity (cost=0.00..11.00 rows=2 width=48) -> Sort (cost=14632.99..14632.99 rows=367 width=112) -> Subquery Scan media_acts (cost=14553.17..14617.36 rows=367 width=112) -> Aggregate (cost=14553.17..14617.36 rows=367 width=112) -> Group (cost=14553.17..14562.34 rows=3668 width=112) -> Sort (cost=14553.17..14553.17 rows=3668 width=112) -> Subquery Scan stats (cost=13969.18..14336.00 rows=3668 width=112) -> Unique (cost=13969.18..14336.00 rows=3668 width=112) -> Sort (cost=13969.18..13969.18 rows=36682 width=112) -> Append (cost=1.31..9744.33 rows=36682 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=20704 width=80) -> Hash Join (cost=1313.31..4930.60 rows=20704 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=1469.06..3659.68 rows=4519 width=112) -> Hash Join (cost=1469.06..3659.68 rows=4519 width=112) -> Hash Join (cost=1467.74..3364.32 rows=4519 width=92) -> Hash Join (cost=689.81..1978.41 rows=4519 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=744 width=32) -> Hash Join (cost=6.62..102.55 rows=744 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=407.59..407.59 rows=11459 width=28) -> 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) EXPLAIN