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 '%pink%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3382853.40..3382857.88 rows=128 width=46) (actual time=699932.943..702979.198 rows=175 loops=1) Buffers: shared hit=30292338 read=740670 dirtied=66 written=2769 -> Sort (cost=3382853.40..3382853.72 rows=128 width=46) (actual time=699917.683..700710.698 rows=3272630 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 558518kB Buffers: shared hit=30292338 read=740670 dirtied=66 written=2769 -> Nested Loop (cost=2715493.37..3382848.92 rows=128 width=46) (actual time=198974.752..676298.965 rows=3272630 loops=1) Buffers: shared hit=30292330 read=740670 dirtied=66 written=2769 -> Nested Loop (cost=2715493.37..3382812.41 rows=128 width=24) (actual time=198974.628..561205.190 rows=3272630 loops=1) Buffers: shared hit=23747070 read=740670 dirtied=66 written=2769 -> Nested Loop (cost=2715493.37..3382562.20 rows=128 width=24) (actual time=198974.585..340294.849 rows=3272630 loops=1) Buffers: shared hit=10818547 read=560763 written=750 -> Merge Join (cost=2715493.37..3382524.93 rows=128 width=28) (actual time=198974.526..224649.599 rows=3272630 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=982582 read=560763 written=750 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.014..16564.132 rows=7999973 loops=1) Buffers: shared hit=328927 read=105282 written=750 -> Sort (cost=2715493.35..2723473.04 rows=3191875 width=28) (actual time=198974.434..202612.376 rows=3272630 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353979kB Buffers: shared hit=653655 read=455481 -> Hash Join (cost=66848.30..2370675.53 rows=3191875 width=28) (actual time=4696.065..194064.938 rows=3272630 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=653652 read=455481 -> Seq Scan on lineitem (cost=0.00..1670258.24 rows=60165024 width=24) (actual time=0.049..68303.304 rows=60045379 loops=1) Buffers: shared hit=649154 read=419454 -> Hash (cost=65522.00..65522.00 rows=106104 width=4) (actual time=4695.687..4695.687 rows=108938 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3830kB Buffers: shared hit=4495 read=36027 -> Seq Scan on part (cost=0.00..65522.00 rows=106104 width=4) (actual time=0.031..4609.901 rows=108938 loops=1) Filter: ((p_name)::text ~~ '%pink%'::text) Rows Removed by Filter: 1891062 Buffers: shared hit=4495 read=36027 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.033..0.034 rows=1 loops=3272630) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9835965 -> Index Scan using pk_orders on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.066..0.066 rows=1 loops=3272630) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12928523 read=179907 dirtied=66 written=2019 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.032..0.032 rows=1 loops=3272630) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6545260 Total runtime: 703088.009 ms (43 rows) COMMIT; COMMIT