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 '%tan%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3495491.29..3495496.19 rows=140 width=46) (actual time=751049.876..754422.407 rows=175 loops=1) Buffers: shared hit=30245270 read=664079 dirtied=55 written=2799 -> Sort (cost=3495491.29..3495491.64 rows=140 width=46) (actual time=751035.198..751967.871 rows=3258904 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556588kB Buffers: shared hit=30245270 read=664079 dirtied=55 written=2799 -> Nested Loop (cost=2825868.50..3495486.30 rows=140 width=46) (actual time=192581.657..729026.873 rows=3258904 loops=1) Buffers: shared hit=30245262 read=664079 dirtied=55 written=2799 -> Nested Loop (cost=2825868.50..3495446.38 rows=140 width=24) (actual time=192581.569..597125.513 rows=3258904 loops=1) Buffers: shared hit=23727454 read=664079 dirtied=55 written=2799 -> Nested Loop (cost=2825868.50..3495173.34 rows=140 width=24) (actual time=192580.740..351373.369 rows=3258904 loops=1) Buffers: shared hit=10888056 read=449914 written=1373 -> Merge Join (cost=2825868.50..3495132.57 rows=140 width=28) (actual time=192578.347..221374.511 rows=3258904 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1092413 read=449870 written=1373 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.008..18921.373 rows=7999985 loops=1) Buffers: shared hit=310670 read=123539 written=713 -> Sort (cost=2825868.47..2834592.30 rows=3489529 width=28) (actual time=192578.153..196705.243 rows=3258904 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352906kB Buffers: shared hit=781743 read=326331 written=660 -> Hash Join (cost=66973.43..2446650.87 rows=3489529 width=28) (actual time=3398.998..186068.684 rows=3258904 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=781740 read=326331 written=660 -> Seq Scan on lineitem (cost=0.00..1668598.31 rows=60105231 width=24) (actual time=0.031..60944.570 rows=59985329 loops=1) Buffers: shared hit=758547 read=308999 written=2 -> Hash (cost=65522.00..65522.00 rows=116114 width=4) (actual time=3398.603..3398.603 rows=108576 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3818kB Buffers: shared hit=23190 read=17332 written=658 -> Seq Scan on part (cost=0.00..65522.00 rows=116114 width=4) (actual time=0.044..3320.334 rows=108576 loops=1) Filter: ((p_name)::text ~~ '%tan%'::text) Rows Removed by Filter: 1891424 Buffers: shared hit=23190 read=17332 written=658 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.038..0.038 rows=1 loops=3258904) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9795643 read=44 -> Index Scan using pk_orders on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.073..0.074 rows=1 loops=3258904) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12839398 read=214165 dirtied=55 written=1426 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.037..0.038 rows=1 loops=3258904) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6517808 Total runtime: 754569.958 ms (43 rows) COMMIT; COMMIT