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 '%beige%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3528972.13..3528977.20 rows=145 width=46) (actual time=184352.167..187383.757 rows=175 loops=1) Buffers: shared hit=30101326 read=802404 written=5 -> Sort (cost=3528972.13..3528972.49 rows=145 width=46) (actual time=184341.487..185199.122 rows=3257398 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556376kB Buffers: shared hit=30101326 read=802404 written=5 -> Nested Loop (cost=2858638.07..3528966.92 rows=145 width=46) (actual time=95786.271..166291.626 rows=3257398 loops=1) Buffers: shared hit=30101318 read=802404 written=5 -> Nested Loop (cost=2858638.07..3528925.57 rows=145 width=24) (actual time=95786.177..157525.804 rows=3257398 loops=1) Buffers: shared hit=23586522 read=802404 written=5 -> Nested Loop (cost=2858638.07..3528638.31 rows=145 width=24) (actual time=95786.120..115676.095 rows=3257398 loops=1) Buffers: shared hit=10691057 read=650705 written=5 -> Merge Join (cost=2858638.07..3528596.09 rows=145 width=28) (actual time=95786.061..104793.653 rows=3257398 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=902451 read=649405 written=5 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.007..4210.112 rows=7999921 loops=1) Buffers: shared hit=263900 read=170308 written=4 -> Sort (cost=2858635.90..2867591.76 rows=3582344 width=28) (actual time=95785.885..97663.729 rows=3257398 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352789kB Buffers: shared hit=638551 read=479097 written=1 -> Hash Join (cost=66998.76..2468653.47 rows=3582344 width=28) (actual time=986.330..92103.183 rows=3257398 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=638548 read=479097 written=1 -> Seq Scan on lineitem (cost=0.00..1683572.36 rows=60645236 width=24) (actual time=0.026..15222.051 rows=59984826 loops=1) Buffers: shared hit=638543 read=438577 written=1 -> Hash (cost=65522.00..65522.00 rows=118141 width=4) (actual time=986.143..986.143 rows=108590 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3818kB Buffers: shared hit=2 read=40520 -> Seq Scan on part (cost=0.00..65522.00 rows=118141 width=4) (actual time=0.016..943.515 rows=108590 loops=1) Filter: ((p_name)::text ~~ '%beige%'::text) Rows Removed by Filter: 1891410 Buffers: shared hit=2 read=40520 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.002..0.003 rows=1 loops=3257398) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9788606 read=1300 -> Index Scan using pk_orders on orders (cost=0.00..1.97 rows=1 width=8) (actual time=0.012..0.012 rows=1 loops=3257398) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12895465 read=151699 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.001..0.002 rows=1 loops=3257398) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6514796 Total runtime: 187505.564 ms (43 rows) COMMIT; COMMIT