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 '%lawn%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3504465.77..3504470.49 rows=135 width=46) (actual time=399143.921..402756.269 rows=175 loops=1) Buffers: shared hit=30016593 read=911209 dirtied=2 written=2924 -> Sort (cost=3504465.77..3504466.10 rows=135 width=46) (actual time=399129.737..400198.851 rows=3260082 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556754kB Buffers: shared hit=30016593 read=911209 dirtied=2 written=2924 -> Nested Loop (cost=2835528.57..3504460.99 rows=135 width=46) (actual time=165371.456..374748.548 rows=3260082 loops=1) Buffers: shared hit=30016585 read=911209 dirtied=2 written=2924 -> Nested Loop (cost=2835528.57..3504422.49 rows=135 width=24) (actual time=165371.369..348353.355 rows=3260082 loops=1) Buffers: shared hit=23496421 read=911209 dirtied=2 written=2924 -> Nested Loop (cost=2835528.57..3504155.04 rows=135 width=24) (actual time=165371.232..226429.779 rows=3260082 loops=1) Buffers: shared hit=10659566 read=690122 written=2427 -> Merge Join (cost=2835528.57..3504115.73 rows=135 width=28) (actual time=165371.167..181824.061 rows=3260082 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=861735 read=690122 written=2427 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.015..8848.248 rows=7999993 loops=1) Buffers: shared hit=321252 read=112957 written=2422 -> Sort (cost=2835528.42..2844027.09 rows=3399471 width=28) (actual time=165371.069..168158.070 rows=3260082 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352998kB Buffers: shared hit=540483 read=577165 written=5 -> Hash Join (cost=66923.39..2466738.87 rows=3399471 width=28) (actual time=3692.973..158892.781 rows=3260082 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=540480 read=577165 written=5 -> Seq Scan on lineitem (cost=0.00..1683567.42 rows=60644742 width=24) (actual time=0.029..43140.448 rows=60044872 loops=1) Buffers: shared hit=536245 read=540875 written=5 -> Hash (cost=65522.00..65522.00 rows=112111 width=4) (actual time=3692.549..3692.549 rows=108565 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3817kB Buffers: shared hit=4232 read=36290 -> Seq Scan on part (cost=0.00..65522.00 rows=112111 width=4) (actual time=0.028..3600.952 rows=108565 loops=1) Filter: ((p_name)::text ~~ '%lawn%'::text) Rows Removed by Filter: 1891435 Buffers: shared hit=4232 read=36290 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.012..0.012 rows=1 loops=3260082) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9797831 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.97 rows=1 width=8) (actual time=0.036..0.036 rows=1 loops=3260082) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3260082 Buffers: shared hit=12836855 read=221087 dirtied=2 written=497 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.005..0.006 rows=1 loops=3260082) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6520164 Total runtime: 402869.578 ms (44 rows) COMMIT; COMMIT