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 '%sky%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3765423.04..3765429.17 rows=175 width=46) (actual time=185611.292..189218.436 rows=175 loops=1) Buffers: shared hit=30534701 read=494342 written=2303 -> Sort (cost=3765423.04..3765423.48 rows=175 width=46) (actual time=185598.297..186742.015 rows=3271991 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 558428kB Buffers: shared hit=30534701 read=494342 written=2303 -> Nested Loop (cost=3089325.92..3765416.53 rows=175 width=46) (actual time=97098.296..166619.579 rows=3271991 loops=1) Buffers: shared hit=30534693 read=494342 written=2303 -> Nested Loop (cost=3089325.92..3765366.62 rows=175 width=24) (actual time=97098.222..156770.643 rows=3271991 loops=1) Buffers: shared hit=23990711 read=494342 written=2303 -> Nested Loop (cost=3089325.92..3765023.95 rows=175 width=24) (actual time=97098.175..117667.565 rows=3271991 loops=1) Buffers: shared hit=10909717 read=469322 written=389 -> Merge Join (cost=3089325.92..3764972.99 rows=175 width=28) (actual time=97098.120..106004.563 rows=3271991 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1075315 read=469068 written=387 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.010..3919.689 rows=7999657 loops=1) Buffers: shared hit=401112 read=33077 written=382 -> Sort (cost=3089323.75..3100175.87 rows=4340847 width=28) (actual time=97097.993..99078.772 rows=3271991 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353929kB Buffers: shared hit=674203 read=435991 written=5 -> Hash Join (cost=67323.91..2610755.24 rows=4340847 width=28) (actual time=1192.936..93673.434 rows=3271991 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=674200 read=435991 written=5 -> Seq Scan on lineitem (cost=0.00..1671921.52 rows=60225552 width=24) (actual time=0.026..15212.649 rows=60045303 loops=1) Buffers: shared hit=661440 read=408226 written=5 -> Hash (cost=65522.00..65522.00 rows=144153 width=4) (actual time=1192.777..1192.777 rows=108866 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3828kB Buffers: shared hit=12757 read=27765 -> Seq Scan on part (cost=0.00..65522.00 rows=144153 width=4) (actual time=0.022..1139.713 rows=108866 loops=1) Filter: ((p_name)::text ~~ '%sky%'::text) Rows Removed by Filter: 1891134 Buffers: shared hit=12757 read=27765 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=3271991) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9834402 read=254 written=2 -> Index Scan using pk_orders on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.011..0.011 rows=1 loops=3271991) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=13080994 read=25020 written=1914 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.002..0.002 rows=1 loops=3271991) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6543982 Total runtime: 189340.283 ms (43 rows) COMMIT; COMMIT