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 '%cornsilk%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3353393.47..3353397.49 rows=115 width=46) (actual time=367529.828..370770.178 rows=175 loops=1) Buffers: shared hit=30493835 read=504473 dirtied=7 written=1941 -> Sort (cost=3353393.47..3353393.75 rows=115 width=46) (actual time=367516.730..368415.199 rows=3268289 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 557908kB Buffers: shared hit=30493835 read=504473 dirtied=7 written=1941 -> Nested Loop (cost=2688238.79..3353389.53 rows=115 width=46) (actual time=165654.353..344845.460 rows=3268289 loops=1) Buffers: shared hit=30493827 read=504473 dirtied=7 written=1941 -> Nested Loop (cost=2688238.79..3353356.73 rows=115 width=24) (actual time=165654.265..319637.146 rows=3268289 loops=1) Buffers: shared hit=23957249 read=504473 dirtied=7 written=1941 -> Nested Loop (cost=2688238.79..3353130.42 rows=115 width=24) (actual time=165654.127..221176.065 rows=3268289 loops=1) Buffers: shared hit=10885780 read=484893 written=1920 -> Merge Join (cost=2688238.79..3353096.94 rows=115 width=28) (actual time=165654.073..182697.424 rows=3268289 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1062693 read=484893 written=1920 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.463..9610.131 rows=7999853 loops=1) Buffers: shared hit=295134 read=139068 written=1918 -> Sort (cost=2688238.66..2695494.39 rows=2902293 width=28) (actual time=165653.551..168348.870 rows=3268289 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353640kB Buffers: shared hit=767559 read=345825 written=2 -> Hash Join (cost=66723.19..2376695.48 rows=2902293 width=28) (actual time=3030.572..160232.779 rows=3268289 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=767556 read=345825 written=2 -> Seq Scan on lineitem (cost=0.00..1676902.68 rows=60404668 width=24) (actual time=0.102..42467.469 rows=60045310 loops=1) Buffers: shared hit=767551 read=305305 written=2 -> Hash (cost=65522.00..65522.00 rows=96095 width=4) (actual time=3029.810..3029.810 rows=108871 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3828kB Buffers: shared hit=2 read=40520 -> Seq Scan on part (cost=0.00..65522.00 rows=96095 width=4) (actual time=0.018..2938.328 rows=108871 loops=1) Filter: ((p_name)::text ~~ '%cornsilk%'::text) Rows Removed by Filter: 1891129 Buffers: shared hit=2 read=40520 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.010..0.011 rows=1 loops=3268289) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9823087 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.96 rows=1 width=8) (actual time=0.029..0.029 rows=1 loops=3268289) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3268289 Buffers: shared hit=13071469 read=19580 dirtied=7 written=21 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.005..0.005 rows=1 loops=3268289) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6536578 Total runtime: 370882.519 ms (44 rows) COMMIT; COMMIT