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=1262411.62..1262416.55 rows=141 width=46) (actual time=127278.751..130309.970 rows=175 loops=1) Group Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Buffers: shared hit=35658772 read=2432355 dirtied=14387 written=14940 -> Sort (cost=1262411.62..1262411.97 rows=141 width=46) (actual time=127267.856..128112.170 rows=3272558 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 558508kB Buffers: shared hit=35658772 read=2432355 dirtied=14387 written=14940 -> Hash Join (cost=66976.27..1262406.58 rows=141 width=46) (actual time=1134.139..117162.738 rows=3272558 loops=1) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) Buffers: shared hit=35658764 read=2432355 dirtied=14387 written=14940 -> Nested Loop (cost=66974.71..1262402.38 rows=141 width=24) (actual time=1134.062..113745.480 rows=3272558 loops=1) Buffers: shared hit=35658760 read=2432355 dirtied=14387 written=14940 -> Nested Loop (cost=66974.27..1262334.04 rows=141 width=24) (actual time=1133.973..59639.600 rows=3272558 loops=1) Buffers: shared hit=23357528 read=1625553 dirtied=13935 written=9451 -> Nested Loop (cost=66973.98..1262288.54 rows=141 width=28) (actual time=1133.960..46381.813 rows=3272558 loops=1) Buffers: shared hit=13521778 read=1625553 dirtied=13935 written=9451 -> Hash Join (cost=66973.41..352575.93 rows=464452 width=16) (actual time=1133.844..6686.081 rows=435752 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=65614 read=145866 written=751 -> Seq Scan on partsupp (cost=0.00..250958.00 rows=8000000 width=12) (actual time=0.017..3228.618 rows=8000000 loops=1) Buffers: shared hit=60692 read=110266 written=724 -> Hash (cost=65522.00..65522.00 rows=116113 width=4) (actual time=1133.149..1133.149 rows=108938 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 4854kB Buffers: shared hit=4922 read=35600 written=27 -> Seq Scan on part (cost=0.00..65522.00 rows=116113 width=4) (actual time=0.023..1088.390 rows=108938 loops=1) Filter: ((p_name)::text ~~ '%pink%'::text) Rows Removed by Filter: 1891062 Buffers: shared hit=4922 read=35600 written=27 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.56..1.95 rows=1 width=24) (actual time=0.018..0.088 rows=8 loops=435752) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: (partsupp.ps_suppkey = l_suppkey) Rows Removed by Filter: 23 Buffers: shared hit=13456164 read=1479687 dirtied=13935 written=8700 -> Index Scan using pk_supplier on supplier (cost=0.29..0.31 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=3272558) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9835750 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.43..0.47 rows=1 width=8) (actual time=0.015..0.016 rows=1 loops=3272558) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3272558 Buffers: shared hit=12301232 read=806802 dirtied=452 written=5489 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.030..0.030 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 10kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.007..0.012 rows=25 loops=1) Buffers: shared hit=1 Planning time: 55.104 ms Execution time: 130389.783 ms (47 rows) COMMIT; COMMIT