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 '%snow%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3376492.21..3376496.51 rows=123 width=46) (actual time=255894.272..259412.100 rows=175 loops=1) Buffers: shared hit=30218644 read=706220 written=7678 -> Sort (cost=3376492.21..3376492.51 rows=123 width=46) (actual time=255878.931..257001.405 rows=3260185 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556768kB Buffers: shared hit=30218644 read=706220 written=7678 -> Nested Loop (cost=2709963.84..3376487.94 rows=123 width=46) (actual time=126569.205..232432.059 rows=3260185 loops=1) Buffers: shared hit=30218636 read=706220 written=7678 -> Nested Loop (cost=2709963.84..3376452.86 rows=123 width=24) (actual time=126569.143..214898.268 rows=3260185 loops=1) Buffers: shared hit=23698266 read=706220 written=7678 -> Nested Loop (cost=2709963.84..3376211.21 rows=123 width=24) (actual time=126569.063..159622.289 rows=3260185 loops=1) Buffers: shared hit=10678693 read=667105 written=7647 -> Merge Join (cost=2709963.84..3376175.39 rows=123 width=28) (actual time=126569.026..139604.613 rows=3260185 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=880088 read=667105 written=7647 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.018..6656.740 rows=7999849 loops=1) Buffers: shared hit=272213 read=161989 written=2518 -> Sort (cost=2709963.83..2717670.17 rows=3082537 width=28) (actual time=126568.960..128856.911 rows=3260185 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353006kB Buffers: shared hit=607875 read=505116 written=5129 -> Hash Join (cost=66798.25..2377732.82 rows=3082537 width=28) (actual time=2186.250..122494.523 rows=3260185 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=607872 read=505116 written=5129 -> Seq Scan on lineitem (cost=0.00..1676282.10 rows=60382710 width=24) (actual time=0.023..23045.014 rows=59985687 loops=1) Buffers: shared hit=601653 read=470810 written=6 -> Hash (cost=65522.00..65522.00 rows=102100 width=4) (actual time=2186.041..2186.041 rows=108717 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3823kB Buffers: shared hit=6216 read=34306 written=5123 -> Seq Scan on part (cost=0.00..65522.00 rows=102100 width=4) (actual time=0.021..1570.665 rows=108717 loops=1) Filter: ((p_name)::text ~~ '%snow%'::text) Rows Removed by Filter: 1891283 Buffers: shared hit=6216 read=34306 written=5123 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=3260185) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9798605 -> Index Scan using pk_orders on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.016..0.016 rows=1 loops=3260185) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=13019573 read=39115 written=31 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.003..0.004 rows=1 loops=3260185) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6520370 Total runtime: 259514.148 ms (43 rows) COMMIT; COMMIT