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 '%forest%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3388249.75..3388254.27 rows=129 width=46) (actual time=284401.476..287946.980 rows=175 loops=1) Buffers: shared hit=30292840 read=611493 dirtied=47 written=2834 -> Sort (cost=3388249.75..3388250.08 rows=129 width=46) (actual time=284387.026..285410.115 rows=3258161 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556483kB Buffers: shared hit=30292840 read=611493 dirtied=47 written=2834 -> Nested Loop (cost=2720838.90..3388245.23 rows=129 width=46) (actual time=124231.579..262060.210 rows=3258161 loops=1) Buffers: shared hit=30292832 read=611493 dirtied=47 written=2834 -> Nested Loop (cost=2720838.90..3388208.44 rows=129 width=24) (actual time=124231.512..240208.404 rows=3258161 loops=1) Buffers: shared hit=23776510 read=611493 dirtied=47 written=2834 -> Nested Loop (cost=2720838.90..3387955.43 rows=129 width=24) (actual time=124231.474..164689.118 rows=3258161 loops=1) Buffers: shared hit=10850505 read=487051 written=1772 -> Merge Join (cost=2720838.90..3387917.86 rows=129 width=28) (actual time=124231.436..138406.433 rows=3258161 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1058426 read=487051 written=1772 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.051..7119.324 rows=7999977 loops=1) Buffers: shared hit=287866 read=146343 written=1771 -> Sort (cost=2720838.34..2728834.02 rows=3198272 width=28) (actual time=124231.325..126946.040 rows=3258161 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352848kB Buffers: shared hit=770560 read=340708 written=1 -> Hash Join (cost=66848.30..2375283.26 rows=3198272 width=28) (actual time=1846.307..120220.988 rows=3258161 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=770557 read=340708 written=1 -> Seq Scan on lineitem (cost=0.00..1673596.12 rows=60285612 width=24) (actual time=0.033..25654.476 rows=60046221 loops=1) Buffers: shared hit=763479 read=307261 written=1 -> Hash (cost=65522.00..65522.00 rows=106104 width=4) (actual time=1846.004..1846.004 rows=108543 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3816kB Buffers: shared hit=7075 read=33447 -> Seq Scan on part (cost=0.00..65522.00 rows=106104 width=4) (actual time=0.035..1769.890 rows=108543 loops=1) Filter: ((p_name)::text ~~ '%forest%'::text) Rows Removed by Filter: 1891457 Buffers: shared hit=7075 read=33447 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.007..0.007 rows=1 loops=3258161) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9792079 -> Index Scan using pk_orders on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.022..0.022 rows=1 loops=3258161) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12926005 read=124442 dirtied=47 written=1062 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.004..0.005 rows=1 loops=3258161) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6516322 Total runtime: 288067.599 ms (43 rows) COMMIT; COMMIT