BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select nation, o_year, sum(amount) as sum_profit from ( select n_name as nation, extract(year from o_orderdate) as o_year, l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount from part, supplier, lineitem, partsupp, orders, nation where s_suppkey = l_suppkey and ps_suppkey = l_suppkey and ps_partkey = l_partkey and p_partkey = l_partkey and o_orderkey = l_orderkey and s_nationkey = n_nationkey and p_name like '%ghost%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3675964.06..3675969.73 rows=162 width=46) (actual time=269625.147..272784.502 rows=175 loops=1) Buffers: shared hit=30170265 read=871870 dirtied=161 written=5316 -> Sort (cost=3675964.06..3675964.46 rows=162 width=46) (actual time=269612.112..270571.901 rows=3272559 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 558508kB Buffers: shared hit=30170265 read=871870 dirtied=161 written=5316 -> Nested Loop (cost=3001884.77..3675958.11 rows=162 width=46) (actual time=120129.077..247511.739 rows=3272559 loops=1) Buffers: shared hit=30170257 read=871870 dirtied=161 written=5316 -> Nested Loop (cost=3001884.77..3675911.91 rows=162 width=24) (actual time=120128.990..228574.731 rows=3272559 loops=1) Buffers: shared hit=23625139 read=871870 dirtied=161 written=5316 -> Nested Loop (cost=3001884.77..3675589.90 rows=162 width=24) (actual time=120128.941..157345.896 rows=3272559 loops=1) Buffers: shared hit=10729178 read=659753 written=2934 -> Merge Join (cost=3001884.77..3675542.44 rows=163 width=28) (actual time=120128.866..133714.102 rows=3272559 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=894830 read=659169 written=2934 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.062..6818.124 rows=7999973 loops=1) Buffers: shared hit=269594 read=164615 written=2915 -> Sort (cost=3001884.76..3012073.01 rows=4075300 width=28) (actual time=120128.707..122537.910 rows=3272559 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353973kB Buffers: shared hit=625236 read=494554 written=19 -> Hash Join (cost=67198.64..2554447.90 rows=4075300 width=28) (actual time=1826.891..116628.043 rows=3272559 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=625233 read=494554 written=19 -> Seq Scan on lineitem (cost=0.00..1686921.67 rows=60765967 width=24) (actual time=0.064..22425.872 rows=60045297 loops=1) Buffers: shared hit=618054 read=461208 written=7 -> Hash (cost=65522.00..65522.00 rows=134131 width=4) (actual time=1826.468..1826.468 rows=108973 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3832kB Buffers: shared hit=7176 read=33346 written=12 -> Seq Scan on part (cost=0.00..65522.00 rows=134131 width=4) (actual time=0.035..1738.310 rows=108973 loops=1) Filter: ((p_name)::text ~~ '%ghost%'::text) Rows Removed by Filter: 1891027 Buffers: shared hit=7176 read=33346 written=12 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=3272559) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9834348 read=584 -> Index Scan using pk_orders on orders (cost=0.00..1.98 rows=1 width=8) (actual time=0.020..0.021 rows=1 loops=3272559) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12895961 read=212117 dirtied=161 written=2382 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.003..0.004 rows=1 loops=3272559) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6545118 Total runtime: 272891.730 ms (43 rows) COMMIT; COMMIT