psql:demo.sql5:31: NOTICE: QUERY PLAN: Limit (cost=602630531.21..602630531.21 rows=10 width=69) -> Sort (cost=602630531.21..602630531.21 rows=218145 width=69) -> Aggregate (cost=602583597.46..602609774.87 rows=218145 width=69) -> Group (cost=602583597.46..602596686.16 rows=2181451 width=69) -> Sort (cost=602583597.46..602583597.46 rows=2181451 width=69) -> Merge Join (cost=602162862.44..602184219.45 rows=2181451 width=69) -> Sort (cost=600998172.01..600998172.01 rows=52125 width=49) -> Merge Join (cost=600994410.42..600994904.87 rows=52125 width=49) -> Sort (cost=13.25..13.25 rows=302 width=25) -> Seq Scan on sc_attr c (cost=0.00..3.30 rows=302 width=25) -> Sort (cost=600994397.17..600994397.17 rows=64485 width=24) -> Seq Scan on sc_customer_attr a (cost=0.00..600990276.11 rows=64485 width=24) SubPlan -> Limit (cost=736.25..736.25 rows=1 width=20) -> Subquery Scan z (cost=736.25..736.25 rows=1 width=20) -> Limit (cost=736.25..736.25 rows=1 width=20) -> Sort (cost=736.25..736.25 rows=1 width=20) -> Aggregate (cost=0.00..736.24 rows=1 width=20) -> Group (cost=0.00..736.24 rows=1 width=20) -> Index Scan using xie2sc_add_points on sc_add_points d (cost=0.00..736.24 rows=1 width=20) -> Sort (cost=1164690.44..1164690.44 rows=7354200 width=20) -> Seq Scan on sc_add_points b (cost=0.00..138679.20 rows=7354200 width=20)