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 '%olive%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3525716.89..3525721.97 rows=145 width=46) (actual time=253632.554..257069.237 rows=175 loops=1) Buffers: shared hit=30228130 read=556798 written=2115 -> Sort (cost=3525716.89..3525717.26 rows=145 width=46) (actual time=253618.424..254630.530 rows=3244659 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 554585kB Buffers: shared hit=30228130 read=556798 written=2115 -> Nested Loop (cost=2855040.92..3525711.69 rows=145 width=46) (actual time=124378.904..231259.386 rows=3244659 loops=1) Buffers: shared hit=30228122 read=556798 written=2115 -> Nested Loop (cost=2855040.92..3525670.33 rows=145 width=24) (actual time=124378.841..213582.154 rows=3244659 loops=1) Buffers: shared hit=23738804 read=556798 written=2115 -> Nested Loop (cost=2855040.92..3525384.99 rows=145 width=24) (actual time=124378.798..157164.347 rows=3244659 loops=1) Buffers: shared hit=10751394 read=547880 written=2110 -> Merge Join (cost=2855040.92..3525342.76 rows=145 width=28) (actual time=124378.755..137027.621 rows=3244659 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=999706 read=547880 written=2110 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.017..6208.097 rows=7999861 loops=1) Buffers: shared hit=322698 read=111504 written=2095 -> Sort (cost=2855040.91..2864110.61 rows=3627881 width=28) (actual time=124378.625..126675.705 rows=3244659 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 351793kB Buffers: shared hit=677008 read=436376 written=15 -> Hash Join (cost=67023.48..2459770.66 rows=3627881 width=28) (actual time=1841.439..119463.962 rows=3244659 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=677005 read=436376 written=15 -> Seq Scan on lineitem (cost=0.00..1676908.88 rows=60405288 width=24) (actual time=0.034..22780.736 rows=60045310 loops=1) Buffers: shared hit=677000 read=395856 written=1 -> Hash (cost=65522.00..65522.00 rows=120118 width=4) (actual time=1841.165..1841.165 rows=108018 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3798kB Buffers: shared hit=2 read=40520 written=14 -> Seq Scan on part (cost=0.00..65522.00 rows=120118 width=4) (actual time=0.030..1763.441 rows=108018 loops=1) Filter: ((p_name)::text ~~ '%olive%'::text) Rows Removed by Filter: 1891982 Buffers: shared hit=2 read=40520 written=14 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=3244659) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9751688 -> Index Scan using pk_orders on orders (cost=0.00..1.96 rows=1 width=8) (actual time=0.016..0.016 rows=1 loops=3244659) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12987410 read=8918 written=5 -> 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=3244659) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6489318 Total runtime: 257152.984 ms (43 rows) COMMIT; COMMIT