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 '%chiffon%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3655235.72..3655241.43 rows=163 width=46) (actual time=306492.820..309844.973 rows=175 loops=1) Buffers: shared hit=30011782 read=865807 written=5362 -> Sort (cost=3655235.72..3655236.13 rows=163 width=46) (actual time=306479.743..307438.161 rows=3255106 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556054kB Buffers: shared hit=30011782 read=865807 written=5362 -> Nested Loop (cost=2981370.21..3655229.73 rows=163 width=46) (actual time=136046.542..285362.451 rows=3255106 loops=1) Buffers: shared hit=30011774 read=865807 written=5362 -> Nested Loop (cost=2981370.21..3655183.24 rows=163 width=24) (actual time=136046.449..260668.847 rows=3255106 loops=1) Buffers: shared hit=23501562 read=865807 written=5362 -> Nested Loop (cost=2981370.21..3654863.01 rows=163 width=24) (actual time=136046.402..181037.963 rows=3255106 loops=1) Buffers: shared hit=10660047 read=669271 written=1637 -> Merge Join (cost=2981370.21..3654815.55 rows=163 width=28) (actual time=136046.352..151854.204 rows=3255106 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=877264 read=669271 written=1637 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.014..8325.044 rows=8000000 loops=1) Buffers: shared hit=298786 read=135423 written=1636 -> Sort (cost=2981369.65..2991487.35 rows=4047080 width=28) (actual time=136046.212..138758.685 rows=3255106 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352610kB Buffers: shared hit=578478 read=533848 written=1 -> Hash Join (cost=67198.64..2537233.99 rows=4047080 width=28) (actual time=2154.443..131403.967 rows=3255106 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=578475 read=533848 written=1 -> Seq Scan on lineitem (cost=0.00..1675249.80 rows=60345180 width=24) (actual time=0.029..27769.920 rows=60045826 loops=1) Buffers: shared hit=578334 read=493464 written=1 -> Hash (cost=65522.00..65522.00 rows=134131 width=4) (actual time=2154.152..2154.152 rows=108461 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3814kB Buffers: shared hit=138 read=40384 -> Seq Scan on part (cost=0.00..65522.00 rows=134131 width=4) (actual time=0.036..2071.935 rows=108461 loops=1) Filter: ((p_name)::text ~~ '%chiffon%'::text) Rows Removed by Filter: 1891539 Buffers: shared hit=138 read=40384 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.007..0.008 rows=1 loops=3255106) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9782783 -> Index Scan using pk_orders on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.023..0.023 rows=1 loops=3255106) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12841515 read=196536 written=3725 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.005..0.005 rows=1 loops=3255106) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6510212 Total runtime: 309959.681 ms (43 rows) COMMIT; COMMIT