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 '%rose%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3385438.90..3385443.14 rows=121 width=46) (actual time=238241.605..241285.527 rows=175 loops=1) Buffers: shared hit=29995968 read=903889 dirtied=137 written=7401 -> Sort (cost=3385438.90..3385439.21 rows=121 width=46) (actual time=238230.004..239125.981 rows=3256821 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556295kB Buffers: shared hit=29995968 read=903889 dirtied=137 written=7401 -> Nested Loop (cost=2719227.39..3385434.72 rows=121 width=46) (actual time=109261.714..218314.654 rows=3256821 loops=1) Buffers: shared hit=29995960 read=903889 dirtied=137 written=7401 -> Nested Loop (cost=2719227.39..3385400.21 rows=121 width=24) (actual time=109261.633..202406.047 rows=3256821 loops=1) Buffers: shared hit=23482318 read=903889 dirtied=137 written=7401 -> Nested Loop (cost=2719227.39..3385159.70 rows=121 width=24) (actual time=109261.510..140120.710 rows=3256821 loops=1) Buffers: shared hit=10672486 read=668860 written=1971 -> Merge Join (cost=2719227.39..3385124.46 rows=121 width=28) (actual time=109261.458..121558.983 rows=3256821 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=885731 read=668268 written=1971 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.008..5928.196 rows=7999957 loops=1) Buffers: shared hit=273241 read=160968 written=1969 -> Sort (cost=2719227.39..2726830.38 rows=3041199 width=28) (actual time=109261.364..111513.014 rows=3256821 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352744kB Buffers: shared hit=612490 read=507300 written=2 -> Hash Join (cost=66773.21..2391747.90 rows=3041199 width=28) (actual time=1320.152..105392.783 rows=3256821 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=612487 read=507300 written=2 -> Seq Scan on lineitem (cost=0.00..1686912.35 rows=60765035 width=24) (actual time=0.020..18967.375 rows=60045297 loops=1) Buffers: shared hit=575787 read=503475 written=2 -> Hash (cost=65522.00..65522.00 rows=100097 width=4) (actual time=1319.708..1319.708 rows=108458 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3813kB Buffers: shared hit=36697 read=3825 -> Seq Scan on part (cost=0.00..65522.00 rows=100097 width=4) (actual time=0.021..1259.673 rows=108458 loops=1) Filter: ((p_name)::text ~~ '%rose%'::text) Rows Removed by Filter: 1891542 Buffers: shared hit=36697 read=3825 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.004..0.005 rows=1 loops=3256821) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9786755 read=592 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.98 rows=1 width=8) (actual time=0.018..0.018 rows=1 loops=3256821) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3256821 Buffers: shared hit=12809832 read=235029 dirtied=137 written=5430 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.003..0.003 rows=1 loops=3256821) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6513642 Total runtime: 241413.169 ms (44 rows) COMMIT; COMMIT