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 '%forest%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3624364.53..3624369.81 rows=151 width=46) (actual time=223235.741..226514.241 rows=175 loops=1) Buffers: shared hit=30288011 read=588521 written=7671 -> Sort (cost=3624364.53..3624364.91 rows=151 width=46) (actual time=223218.584..224188.508 rows=3254895 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556024kB Buffers: shared hit=30288011 read=588521 written=7671 -> Nested Loop (cost=2952327.39..3624359.06 rows=151 width=46) (actual time=108801.953..204011.224 rows=3254895 loops=1) Buffers: shared hit=30288003 read=588521 written=7671 -> Nested Loop (cost=2952327.39..3624316.00 rows=151 width=24) (actual time=108801.828..188730.824 rows=3254895 loops=1) Buffers: shared hit=23778213 read=588521 written=7671 -> Nested Loop (cost=2952327.39..3624019.34 rows=151 width=24) (actual time=108801.691..138001.848 rows=3254895 loops=1) Buffers: shared hit=10770892 read=558510 written=7663 -> Merge Join (cost=2952327.39..3623975.37 rows=151 width=28) (actual time=108801.636..120647.762 rows=3254895 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=988638 read=558510 written=7663 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.009..5810.487 rows=7999977 loops=1) Buffers: shared hit=266482 read=167727 written=3089 -> Sort (cost=2952327.39..2961847.26 rows=3807947 width=28) (actual time=108801.543..110939.118 rows=3254895 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352593kB Buffers: shared hit=722156 read=390783 written=4574 -> Hash Join (cost=67098.69..2536107.70 rows=3807947 width=28) (actual time=1779.686..105330.228 rows=3254895 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=722153 read=390783 written=4574 -> Seq Scan on lineitem (cost=0.00..1676193.13 rows=60378913 width=24) (actual time=0.054..18124.270 rows=59985687 loops=1) Buffers: shared hit=716772 read=355639 written=6 -> Hash (cost=65522.00..65522.00 rows=126135 width=4) (actual time=1779.095..1779.095 rows=108543 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3816kB Buffers: shared hit=5378 read=35144 written=4568 -> Seq Scan on part (cost=0.00..65522.00 rows=126135 width=4) (actual time=0.019..1704.203 rows=108543 loops=1) Filter: ((p_name)::text ~~ '%forest%'::text) Rows Removed by Filter: 1891457 Buffers: shared hit=5378 read=35144 written=4568 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.004..0.004 rows=1 loops=3254895) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9782254 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.014..0.015 rows=1 loops=3254895) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3254895 Buffers: shared hit=13007321 read=30011 written=8 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.002..0.003 rows=1 loops=3254895) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6509790 Total runtime: 226611.245 ms (44 rows) COMMIT; COMMIT