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 '%beige%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3492685.49..3492690.35 rows=139 width=46) (actual time=94523.627..96724.031 rows=175 loops=1) Buffers: shared hit=29954880 read=972865 written=7313 -> Sort (cost=3492685.49..3492685.83 rows=139 width=46) (actual time=94514.989..94921.959 rows=3261224 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556914kB Buffers: shared hit=29954880 read=972865 written=7313 -> Nested Loop (cost=2823092.81..3492680.54 rows=139 width=46) (actual time=34573.125..80536.180 rows=3261224 loops=1) Buffers: shared hit=29954872 read=972865 written=7313 -> Nested Loop (cost=2823092.81..3492640.90 rows=139 width=24) (actual time=34573.014..74482.584 rows=3261224 loops=1) Buffers: shared hit=23432424 read=972865 written=7313 -> Nested Loop (cost=2823092.81..3492370.10 rows=139 width=24) (actual time=34572.746..50570.321 rows=3261224 loops=1) Buffers: shared hit=10664087 read=678517 written=1959 -> Merge Join (cost=2823092.81..3492329.62 rows=139 width=28) (actual time=34572.687..42762.096 rows=3261224 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=862694 read=678517 written=1959 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.009..3886.781 rows=7999921 loops=1) Buffers: shared hit=416611 read=17597 written=1959 -> Sort (cost=2823092.66..2831807.88 rows=3486086 width=28) (actual time=34572.428..36262.110 rows=3261224 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353088kB Buffers: shared hit=446083 read=660920 -> Hash Join (cost=66973.44..2444274.05 rows=3486086 width=28) (actual time=714.590..31989.695 rows=3261224 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=446080 read=660920 -> Seq Scan on lineitem (cost=0.00..1666929.00 rows=60045400 width=24) (actual time=0.006..10965.049 rows=60045669 loops=1) Buffers: shared hit=405555 read=660920 -> Hash (cost=65522.00..65522.00 rows=116115 width=4) (actual time=714.427..714.427 rows=108590 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3818kB Buffers: shared hit=40522 -> Seq Scan on part (cost=0.00..65522.00 rows=116115 width=4) (actual time=0.018..687.358 rows=108590 loops=1) Filter: ((p_name)::text ~~ '%beige%'::text) Rows Removed by Filter: 1891410 Buffers: shared hit=40522 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=3261224) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9801393 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.007..0.007 rows=1 loops=3261224) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3261224 Buffers: shared hit=12768337 read=294348 written=5354 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.001..0.001 rows=1 loops=3261224) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6522448 Total runtime: 96762.886 ms (44 rows) COMMIT; COMMIT