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 '%violet%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3477157.15..3477161.77 rows=132 width=46) (actual time=275389.631..279063.652 rows=175 loops=1) Buffers: shared hit=30440837 read=579891 written=3072 -> Sort (cost=3477157.15..3477157.48 rows=132 width=46) (actual time=275375.640..276488.010 rows=3270804 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 558261kB Buffers: shared hit=30440837 read=579891 written=3072 -> Nested Loop (cost=2809239.04..3477152.50 rows=132 width=46) (actual time=127174.189..254125.512 rows=3270804 loops=1) Buffers: shared hit=30440829 read=579891 written=3072 -> Nested Loop (cost=2809239.04..3477114.85 rows=132 width=24) (actual time=127174.104..233708.088 rows=3270804 loops=1) Buffers: shared hit=23899221 read=579891 written=3072 -> Nested Loop (cost=2809239.04..3477076.71 rows=131 width=28) (actual time=127174.070..209703.178 rows=3270804 loops=1) Buffers: shared hit=14068826 read=579891 written=3072 -> Merge Join (cost=2809239.04..3476818.91 rows=131 width=28) (actual time=127173.996..141145.663 rows=3270804 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=970273 read=577319 written=3064 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.010..7009.092 rows=7999953 loops=1) Buffers: shared hit=306296 read=127912 written=3061 -> Sort (cost=2809238.48..2817401.13 rows=3265058 width=28) (actual time=127173.612..129714.185 rows=3270804 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353836kB Buffers: shared hit=663977 read=449407 written=3 -> Hash Join (cost=66873.32..2455980.80 rows=3265058 width=28) (actual time=2255.246..122069.035 rows=3270804 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=663974 read=449407 written=3 -> Seq Scan on lineitem (cost=0.00..1676903.48 rows=60404748 width=24) (actual time=0.027..27181.840 rows=60045310 loops=1) Buffers: shared hit=656039 read=416817 written=3 -> Hash (cost=65522.00..65522.00 rows=108106 width=4) (actual time=2255.030..2255.030 rows=108908 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3829kB Buffers: shared hit=7932 read=32590 -> Seq Scan on part (cost=0.00..65522.00 rows=108106 width=4) (actual time=0.057..2168.926 rows=108908 loops=1) Filter: ((p_name)::text ~~ '%violet%'::text) Rows Removed by Filter: 1891092 Buffers: shared hit=7932 read=32590 -> Index Scan using pk_orders on orders (cost=0.00..1.96 rows=1 width=8) (actual time=0.019..0.020 rows=1 loops=3270804) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=13098553 read=2572 written=8 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=3270804) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9830395 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.004..0.004 rows=1 loops=3270804) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6541608 Total runtime: 279193.751 ms (43 rows) COMMIT; COMMIT