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 '%hot%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3374742.83..3374747.03 rows=120 width=46) (actual time=415500.046..419201.061 rows=175 loops=1) Buffers: shared hit=30485579 read=503984 dirtied=33 written=1802 -> Sort (cost=3374742.83..3374743.13 rows=120 width=46) (actual time=415484.152..416604.066 rows=3267129 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 557745kB Buffers: shared hit=30485579 read=503984 dirtied=33 written=1802 -> Nested Loop (cost=2708622.61..3374738.69 rows=120 width=46) (actual time=132070.393..393648.604 rows=3267129 loops=1) Buffers: shared hit=30485571 read=503984 dirtied=33 written=1802 -> Nested Loop (cost=2708622.61..3374704.47 rows=120 width=24) (actual time=132070.305..360664.593 rows=3267129 loops=1) Buffers: shared hit=23951313 read=503984 dirtied=33 written=1802 -> Nested Loop (cost=2708622.61..3374467.53 rows=120 width=24) (actual time=132070.180..209602.377 rows=3267129 loops=1) Buffers: shared hit=11046062 read=322698 written=140 -> Merge Join (cost=2708622.61..3374432.58 rows=120 width=28) (actual time=132070.125..149442.589 rows=3267129 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1227014 read=322698 written=140 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.016..9376.359 rows=7999945 loops=1) Buffers: shared hit=379178 read=55030 written=140 -> Sort (cost=2708622.48..2716195.47 rows=3029197 width=28) (actual time=132069.905..135015.376 rows=3267129 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353549kB Buffers: shared hit=847836 read=267668 -> Hash Join (cost=66773.24..2382521.79 rows=3029197 width=28) (actual time=2825.889..126565.542 rows=3267129 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=847833 read=267668 -> Seq Scan on lineitem (cost=0.00..1680216.29 rows=60524029 width=24) (actual time=0.027..28698.687 rows=60044082 loops=1) Buffers: shared hit=842074 read=232902 -> Hash (cost=65522.00..65522.00 rows=100099 width=4) (actual time=2825.453..2825.453 rows=108843 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3827kB Buffers: shared hit=5756 read=34766 -> Seq Scan on part (cost=0.00..65522.00 rows=100099 width=4) (actual time=0.124..2729.801 rows=108843 loops=1) Filter: ((p_name)::text ~~ '%hot%'::text) Rows Removed by Filter: 1891157 Buffers: shared hit=5756 read=34766 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.017..0.017 rows=1 loops=3267129) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9819048 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.96 rows=1 width=8) (actual time=0.045..0.045 rows=1 loops=3267129) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3267129 Buffers: shared hit=12905251 read=181286 dirtied=33 written=1662 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.007..0.008 rows=1 loops=3267129) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6534258 Total runtime: 419304.550 ms (44 rows) COMMIT; COMMIT