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 '%thistle%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=1162687.93..1162692.48 rows=130 width=46) (actual time=90676.780..93540.290 rows=175 loops=1) Group Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Buffers: shared hit=35934538 read=1788771 dirtied=18574 written=22010 -> Sort (cost=1162687.93..1162688.25 rows=130 width=46) (actual time=90666.454..91316.911 rows=3242404 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 554268kB Buffers: shared hit=35934538 read=1788771 dirtied=18574 written=22010 -> Hash Join (cost=66876.18..1162683.36 rows=130 width=46) (actual time=895.296..84515.121 rows=3242404 loops=1) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) Buffers: shared hit=35934530 read=1788771 dirtied=18574 written=22010 -> Nested Loop (cost=66874.62..1162679.36 rows=130 width=24) (actual time=895.236..81284.487 rows=3242404 loops=1) Buffers: shared hit=35934526 read=1788771 dirtied=18574 written=22010 -> Nested Loop (cost=66874.18..1162616.36 rows=130 width=24) (actual time=895.196..50802.334 rows=3242404 loops=1) Buffers: shared hit=23353901 read=1382063 dirtied=18335 written=15306 -> Nested Loop (cost=66873.89..1162574.41 rows=130 width=28) (actual time=895.187..40263.774 rows=3242404 loops=1) Buffers: shared hit=13609242 read=1382063 dirtied=18335 written=15306 -> Hash Join (cost=66873.32..352112.02 rows=428069 width=16) (actual time=895.028..4992.422 rows=432128 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=76968 read=134512 written=1468 -> Seq Scan on partsupp (cost=0.00..250958.00 rows=8000000 width=12) (actual time=0.006..2283.137 rows=8000000 loops=1) Buffers: shared hit=61018 read=109940 written=1468 -> Hash (cost=65522.00..65522.00 rows=108106 width=4) (actual time=894.482..894.482 rows=108032 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 4822kB Buffers: shared hit=15950 read=24572 -> Seq Scan on part (cost=0.00..65522.00 rows=108106 width=4) (actual time=0.011..854.981 rows=108032 loops=1) Filter: ((p_name)::text ~~ '%thistle%'::text) Rows Removed by Filter: 1891968 Buffers: shared hit=15950 read=24572 -> Index Scan using lineitem_l_partkey_l_quantity_idx on lineitem (cost=0.56..1.88 rows=1 width=24) (actual time=0.015..0.079 rows=8 loops=432128) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: (partsupp.ps_suppkey = l_suppkey) Rows Removed by Filter: 23 Buffers: shared hit=13532274 read=1247551 dirtied=18335 written=13838 -> Index Scan using pk_supplier on supplier (cost=0.29..0.31 rows=1 width=8) (actual time=0.002..0.003 rows=1 loops=3242404) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9744659 -> Index Scan using pk_orders on orders (cost=0.43..0.47 rows=1 width=8) (actual time=0.008..0.009 rows=1 loops=3242404) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12580625 read=406708 dirtied=239 written=6704 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.019..0.019 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.004..0.006 rows=25 loops=1) Buffers: shared hit=1 Planning time: 34.208 ms Execution time: 93568.859 ms (46 rows) COMMIT; COMMIT