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 '%plum%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=994133.02..994136.48 rows=99 width=46) (actual time=120995.317..124723.184 rows=175 loops=1) Group Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Buffers: shared hit=35627562 read=2356511 dirtied=14561 written=17522 -> Sort (cost=994133.02..994133.27 rows=99 width=46) (actual time=120982.952..122383.003 rows=3262688 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 557120kB Buffers: shared hit=35627562 read=2356511 dirtied=14561 written=17522 -> Hash Join (cost=66550.87..994129.74 rows=99 width=46) (actual time=1067.691..108194.476 rows=3262688 loops=1) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) Buffers: shared hit=35627554 read=2356511 dirtied=14561 written=17522 -> Nested Loop (cost=66549.30..994126.32 rows=99 width=24) (actual time=1067.631..105071.071 rows=3262688 loops=1) Buffers: shared hit=35627550 read=2356511 dirtied=14561 written=17522 -> Nested Loop (cost=66548.87..994078.34 rows=99 width=24) (actual time=1067.494..55536.552 rows=3262688 loops=1) Buffers: shared hit=23287756 read=1627617 dirtied=14365 written=10706 -> Nested Loop (cost=66548.58..994046.39 rows=99 width=28) (actual time=1067.475..42633.257 rows=3262688 loops=1) Buffers: shared hit=13482377 read=1627617 dirtied=14365 written=10706 -> Hash Join (cost=66548.01..350789.25 rows=328324 width=16) (actual time=1067.312..5894.237 rows=434892 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=58396 read=153084 written=674 -> Seq Scan on partsupp (cost=0.00..250958.00 rows=8000000 width=12) (actual time=0.006..2607.883 rows=8000000 loops=1) Buffers: shared hit=56584 read=114374 written=579 -> Hash (cost=65522.00..65522.00 rows=82081 width=4) (actual time=1066.483..1066.483 rows=108723 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 4847kB Buffers: shared hit=1812 read=38710 written=95 -> Seq Scan on part (cost=0.00..65522.00 rows=82081 width=4) (actual time=0.068..1024.743 rows=108723 loops=1) Filter: ((p_name)::text ~~ '%plum%'::text) Rows Removed by Filter: 1891277 Buffers: shared hit=1812 read=38710 written=95 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.56..1.95 rows=1 width=24) (actual time=0.017..0.082 rows=8 loops=434892) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: (partsupp.ps_suppkey = l_suppkey) Rows Removed by Filter: 23 Buffers: shared hit=13423981 read=1474533 dirtied=14365 written=10032 -> Index Scan using pk_supplier on supplier (cost=0.29..0.31 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=3262688) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9805379 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.43..0.47 rows=1 width=8) (actual time=0.014..0.015 rows=1 loops=3262688) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3262688 Buffers: shared hit=12339794 read=728894 dirtied=196 written=6816 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.021..0.021 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 10kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.006..0.010 rows=25 loops=1) Buffers: shared hit=1 Planning time: 32.889 ms Execution time: 124782.249 ms (47 rows) COMMIT; COMMIT