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=3474141.33..3474145.95 rows=132 width=46) (actual time=457747.300..461289.963 rows=175 loops=1) Buffers: shared hit=30274635 read=664163 dirtied=13 written=3040 -> Sort (cost=3474141.33..3474141.66 rows=132 width=46) (actual time=457733.717..458799.047 rows=3262059 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 557032kB Buffers: shared hit=30274635 read=664163 dirtied=13 written=3040 -> Nested Loop (cost=2805868.60..3474136.68 rows=132 width=46) (actual time=170327.799..435809.483 rows=3262059 loops=1) Buffers: shared hit=30274627 read=664163 dirtied=13 written=3040 -> Nested Loop (cost=2805868.60..3474099.03 rows=132 width=24) (actual time=170326.681..403595.665 rows=3262059 loops=1) Buffers: shared hit=23750509 read=664163 dirtied=13 written=3040 -> Nested Loop (cost=2805868.60..3473841.00 rows=132 width=24) (actual time=170326.554..250160.219 rows=3262059 loops=1) Buffers: shared hit=10798326 read=550183 written=604 -> Merge Join (cost=2805868.60..3473802.57 rows=132 width=28) (actual time=170326.513..189542.130 rows=3262059 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=993162 read=550183 written=604 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.026..11010.921 rows=7999985 loops=1) Buffers: shared hit=348228 read=85981 written=604 -> Sort (cost=2805868.46..2814149.41 rows=3312381 width=28) (actual time=170326.362..173386.770 rows=3262059 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353153kB Buffers: shared hit=644934 read=464202 -> Hash Join (cost=66898.36..2447146.92 rows=3312381 width=28) (actual time=2478.073..163245.759 rows=3262059 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=644931 read=464202 -> Seq Scan on lineitem (cost=0.00..1670262.94 rows=60165494 width=24) (actual time=0.027..43452.158 rows=60045379 loops=1) Buffers: shared hit=632494 read=436114 -> Hash (cost=65522.00..65522.00 rows=110109 width=4) (actual time=2476.368..2476.368 rows=108576 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3818kB Buffers: shared hit=12434 read=28088 -> Seq Scan on part (cost=0.00..65522.00 rows=110109 width=4) (actual time=0.036..2292.533 rows=108576 loops=1) Filter: ((p_name)::text ~~ '%tan%'::text) Rows Removed by Filter: 1891424 Buffers: shared hit=12434 read=28088 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.017..0.017 rows=1 loops=3262059) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9805164 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.045..0.046 rows=1 loops=3262059) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3262059 Buffers: shared hit=12952183 read=113980 dirtied=13 written=2436 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.007..0.007 rows=1 loops=3262059) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6524118 Total runtime: 461427.732 ms (44 rows) COMMIT; COMMIT