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 '%pink%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3385516.21..3385520.66 rows=127 width=46) (actual time=226048.694..229468.891 rows=175 loops=1) Buffers: shared hit=30558614 read=475161 dirtied=37 written=985 -> Sort (cost=3385516.21..3385516.53 rows=127 width=46) (actual time=226037.471..227059.979 rows=3272599 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 558514kB Buffers: shared hit=30558614 read=475161 dirtied=37 written=985 -> Nested Loop (cost=2718139.15..3385511.77 rows=127 width=46) (actual time=104283.139..202886.155 rows=3272599 loops=1) Buffers: shared hit=30558606 read=475161 dirtied=37 written=985 -> Nested Loop (cost=2718139.15..3385475.55 rows=127 width=24) (actual time=104283.038..187157.269 rows=3272599 loops=1) Buffers: shared hit=24013408 read=475161 dirtied=37 written=985 -> Nested Loop (cost=2718139.15..3385226.88 rows=127 width=24) (actual time=104282.893..132797.802 rows=3272599 loops=1) Buffers: shared hit=10951603 read=428669 -> Merge Join (cost=2718139.15..3385189.90 rows=127 width=28) (actual time=104282.835..114950.209 rows=3272599 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1115755 read=428648 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.019..4416.696 rows=7999973 loops=1) Buffers: shared hit=434209 -> Sort (cost=2718139.15..2726126.68 rows=3195014 width=28) (actual time=104282.735..106509.281 rows=3272599 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353976kB Buffers: shared hit=681546 read=428648 -> Hash Join (cost=66848.29..2372959.57 rows=3195014 width=28) (actual time=1580.730..100596.882 rows=3272599 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=681543 read=428648 -> Seq Scan on lineitem (cost=0.00..1671913.57 rows=60224757 width=24) (actual time=0.047..19019.150 rows=60045303 loops=1) Buffers: shared hit=674482 read=395184 -> Hash (cost=65522.00..65522.00 rows=106103 width=4) (actual time=1580.365..1580.365 rows=108938 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3830kB Buffers: shared hit=7058 read=33464 -> Seq Scan on part (cost=0.00..65522.00 rows=106103 width=4) (actual time=0.027..1505.349 rows=108938 loops=1) Filter: ((p_name)::text ~~ '%pink%'::text) Rows Removed by Filter: 1891062 Buffers: shared hit=7058 read=33464 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.004..0.004 rows=1 loops=3272599) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9835848 read=21 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.015..0.016 rows=1 loops=3272599) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3272599 Buffers: shared hit=13061805 read=46492 dirtied=37 written=985 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.003..0.003 rows=1 loops=3272599) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6545198 Total runtime: 229575.920 ms (44 rows) COMMIT; COMMIT