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 '%goldenrod%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=1183450.14..1183454.65 rows=129 width=46) (actual time=127615.856..130551.142 rows=175 loops=1) Group Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Buffers: shared hit=35307604 read=2438748 dirtied=13484 written=16983 -> Sort (cost=1183450.14..1183450.46 rows=129 width=46) (actual time=127604.571..128453.003 rows=3242643 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 554301kB Buffers: shared hit=35307604 read=2438748 dirtied=13484 written=16983 -> Hash Join (cost=66851.14..1183445.62 rows=129 width=46) (actual time=1163.288..115186.118 rows=3242643 loops=1) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) Buffers: shared hit=35307596 read=2438748 dirtied=13484 written=16983 -> Nested Loop (cost=66849.58..1183441.64 rows=129 width=24) (actual time=1163.204..111706.400 rows=3242643 loops=1) Buffers: shared hit=35307592 read=2438748 dirtied=13484 written=16983 -> Nested Loop (cost=66849.15..1183379.11 rows=129 width=24) (actual time=1163.105..57718.904 rows=3242643 loops=1) Buffers: shared hit=23132435 read=1625491 dirtied=13141 written=10661 -> Nested Loop (cost=66848.85..1183337.49 rows=129 width=28) (actual time=1163.093..44521.410 rows=3242643 loops=1) Buffers: shared hit=13387235 read=1625491 dirtied=13141 written=10661 -> Hash Join (cost=66848.29..352050.41 rows=424412 width=16) (actual time=1163.045..6546.396 rows=432552 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=68572 read=142908 written=870 -> Seq Scan on partsupp (cost=0.00..250958.00 rows=8000000 width=12) (actual time=0.008..2921.647 rows=8000000 loops=1) Buffers: shared hit=59238 read=111720 written=809 -> Hash (cost=65522.00..65522.00 rows=106103 width=4) (actual time=1162.273..1162.273 rows=108138 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 4826kB Buffers: shared hit=9334 read=31188 written=61 -> Seq Scan on part (cost=0.00..65522.00 rows=106103 width=4) (actual time=0.018..1115.749 rows=108138 loops=1) Filter: ((p_name)::text ~~ '%goldenrod%'::text) Rows Removed by Filter: 1891862 Buffers: shared hit=9334 read=31188 written=61 -> 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.017..0.085 rows=7 loops=432552) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: (partsupp.ps_suppkey = l_suppkey) Rows Removed by Filter: 22 Buffers: shared hit=13318663 read=1482583 dirtied=13141 written=9791 -> 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=3242643) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9745200 -> 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=3242643) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3242643 Buffers: shared hit=12175157 read=813257 dirtied=343 written=6322 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.022..0.022 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.006..0.010 rows=25 loops=1) Buffers: shared hit=1 Planning time: 33.021 ms Execution time: 130604.978 ms (47 rows) COMMIT; COMMIT