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 '%blanched%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3514446.74..3514451.81 rows=145 width=46) (actual time=258003.066..261294.928 rows=175 loops=1) Buffers: shared hit=30435811 read=519357 dirtied=8 written=1707 -> Sort (cost=3514446.74..3514447.10 rows=145 width=46) (actual time=257987.466..258963.820 rows=3264071 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 557314kB Buffers: shared hit=30435811 read=519357 dirtied=8 written=1707 -> Nested Loop (cost=2843881.79..3514441.53 rows=145 width=46) (actual time=120096.106..237232.805 rows=3264071 loops=1) Buffers: shared hit=30435803 read=519357 dirtied=8 written=1707 -> Nested Loop (cost=2843881.79..3514400.18 rows=145 width=24) (actual time=120096.036..218753.141 rows=3264071 loops=1) Buffers: shared hit=23907661 read=519357 dirtied=8 written=1707 -> Nested Loop (cost=2843881.79..3514116.74 rows=145 width=24) (actual time=120095.930..154753.750 rows=3264071 loops=1) Buffers: shared hit=10932910 read=419974 written=923 -> Merge Join (cost=2843881.79..3514074.51 rows=145 width=28) (actual time=120095.898..133431.678 rows=3264071 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1123370 read=419974 written=923 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.009..6157.109 rows=7999953 loops=1) Buffers: shared hit=323520 read=110688 written=923 -> Sort (cost=2843881.67..2852915.37 rows=3613482 width=28) (actual time=120095.781..122901.596 rows=3264071 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353310kB Buffers: shared hit=799850 read=309286 -> Hash Join (cost=67023.48..2450283.89 rows=3613482 width=28) (actual time=1803.003..115339.551 rows=3264071 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=799847 read=309286 -> Seq Scan on lineitem (cost=0.00..1670263.34 rows=60165534 width=24) (actual time=0.037..22624.358 rows=60045379 loops=1) Buffers: shared hit=788035 read=280573 -> Hash (cost=65522.00..65522.00 rows=120118 width=4) (actual time=1802.628..1802.628 rows=108755 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3824kB Buffers: shared hit=11809 read=28713 -> Seq Scan on part (cost=0.00..65522.00 rows=120118 width=4) (actual time=0.017..1549.786 rows=108755 loops=1) Filter: ((p_name)::text ~~ '%blanched%'::text) Rows Removed by Filter: 1891245 Buffers: shared hit=11809 read=28713 -> 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=3264071) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9809540 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.018..0.019 rows=1 loops=3264071) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3264071 Buffers: shared hit=12974751 read=99383 dirtied=8 written=784 -> 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=3264071) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6528142 Total runtime: 261429.652 ms (44 rows) COMMIT; COMMIT