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 '%floral%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3470402.34..3470406.96 rows=132 width=46) (actual time=276385.498..279873.523 rows=175 loops=1) Buffers: shared hit=29943551 read=768340 dirtied=135 written=2639 -> Sort (cost=3470402.34..3470402.67 rows=132 width=46) (actual time=276371.857..277480.124 rows=3237167 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 553531kB Buffers: shared hit=29943551 read=768340 dirtied=135 written=2639 -> Nested Loop (cost=2802163.60..3470397.69 rows=132 width=46) (actual time=127485.874..255628.888 rows=3237167 loops=1) Buffers: shared hit=29943543 read=768340 dirtied=135 written=2639 -> Nested Loop (cost=2802163.60..3470360.05 rows=132 width=24) (actual time=127485.796..235478.316 rows=3237167 loops=1) Buffers: shared hit=23469209 read=768340 dirtied=135 written=2639 -> Nested Loop (cost=2802163.60..3470102.89 rows=132 width=24) (actual time=127485.683..164609.361 rows=3237167 loops=1) Buffers: shared hit=10714833 read=556167 written=2134 -> Merge Join (cost=2802163.60..3470064.45 rows=132 width=28) (actual time=127485.630..142078.960 rows=3237167 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=986172 read=555734 written=2134 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.022..6894.700 rows=7999861 loops=1) Buffers: shared hit=263238 read=170964 written=1157 -> Sort (cost=2802163.49..2810433.27 rows=3307915 width=28) (actual time=127485.535..130654.212 rows=3237167 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 351208kB Buffers: shared hit=722934 read=384770 written=977 -> Hash Join (cost=66898.35..2443957.79 rows=3307915 width=28) (actual time=1374.937..121715.081 rows=3237167 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=722931 read=384770 written=977 -> Seq Scan on lineitem (cost=0.00..1668025.08 rows=60084908 width=24) (actual time=0.037..22737.224 rows=59985329 loops=1) Buffers: shared hit=692920 read=374256 written=5 -> Hash (cost=65522.00..65522.00 rows=110108 width=4) (actual time=1374.605..1374.605 rows=107877 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3793kB Buffers: shared hit=30008 read=10514 written=972 -> Seq Scan on part (cost=0.00..65522.00 rows=110108 width=4) (actual time=0.032..1304.751 rows=107877 loops=1) Filter: ((p_name)::text ~~ '%floral%'::text) Rows Removed by Filter: 1892123 Buffers: shared hit=30008 read=10514 written=972 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.005..0.006 rows=1 loops=3237167) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9728661 read=433 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.020..0.021 rows=1 loops=3237167) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3237167 Buffers: shared hit=12754376 read=212173 dirtied=135 written=505 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.004..0.004 rows=1 loops=3237167) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6474334 Total runtime: 280046.474 ms (44 rows) COMMIT; COMMIT