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 '%steel%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3493008.66..3493013.45 rows=137 width=46) (actual time=212434.194..215975.689 rows=175 loops=1) Buffers: shared hit=30377133 read=580971 dirtied=27 written=5014 -> Sort (cost=3493008.66..3493009.00 rows=137 width=46) (actual time=212418.314..213541.910 rows=3264234 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 557337kB Buffers: shared hit=30377133 read=580971 dirtied=27 written=5014 -> Nested Loop (cost=2823802.27..3493003.80 rows=137 width=46) (actual time=103241.412..191499.942 rows=3264234 loops=1) Buffers: shared hit=30377125 read=580971 dirtied=27 written=5014 -> Nested Loop (cost=2823802.27..3492964.72 rows=137 width=24) (actual time=103241.341..178290.723 rows=3264234 loops=1) Buffers: shared hit=23848657 read=580971 dirtied=27 written=5014 -> Nested Loop (cost=2823802.27..3492696.47 rows=137 width=24) (actual time=103241.308..129217.611 rows=3264234 loops=1) Buffers: shared hit=10841871 read=512922 written=384 -> Merge Join (cost=2823802.27..3492656.57 rows=137 width=28) (actual time=103241.266..114031.174 rows=3264234 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1031583 read=512819 written=384 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.26 rows=8000000 width=12) (actual time=0.008..4824.610 rows=7999945 loops=1) Buffers: shared hit=341681 read=92527 written=354 -> Sort (cost=2823797.20..2832387.75 rows=3436219 width=28) (actual time=103241.118..105539.859 rows=3264234 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353323kB Buffers: shared hit=689902 read=420292 written=30 -> Hash Join (cost=66948.41..2450754.56 rows=3436219 width=28) (actual time=1303.087..99862.719 rows=3264234 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=689899 read=420292 written=30 -> Seq Scan on lineitem (cost=0.00..1671914.45 rows=60224845 width=24) (actual time=0.017..17493.441 rows=60045303 loops=1) Buffers: shared hit=677037 read=392629 written=5 -> Hash (cost=65522.00..65522.00 rows=114113 width=4) (actual time=1302.844..1302.844 rows=108737 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3823kB Buffers: shared hit=12859 read=27663 written=25 -> Seq Scan on part (cost=0.00..65522.00 rows=114113 width=4) (actual time=0.026..1241.329 rows=108737 loops=1) Filter: ((p_name)::text ~~ '%steel%'::text) Rows Removed by Filter: 1891263 Buffers: shared hit=12859 read=27663 written=25 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.003..0.004 rows=1 loops=3264234) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9810288 read=103 -> Index Scan using pk_orders on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.014..0.014 rows=1 loops=3264234) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=13006786 read=68049 dirtied=27 written=4630 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.002..0.003 rows=1 loops=3264234) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6528468 Total runtime: 216099.426 ms (43 rows) COMMIT; COMMIT