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 '%chartreuse%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3509766.52..3509771.35 rows=138 width=46) (actual time=257339.518..260794.117 rows=175 loops=1) Buffers: shared hit=30120396 read=676672 dirtied=8 written=13717 -> Sort (cost=3509766.52..3509766.86 rows=138 width=46) (actual time=257327.058..258367.953 rows=3245664 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 554726kB Buffers: shared hit=30120396 read=676672 dirtied=8 written=13717 -> Nested Loop (cost=2840392.35..3509761.61 rows=138 width=46) (actual time=126436.265..233810.657 rows=3245664 loops=1) Buffers: shared hit=30120388 read=676672 dirtied=8 written=13717 -> Nested Loop (cost=2840392.35..3509722.26 rows=138 width=24) (actual time=126436.195..217128.680 rows=3245664 loops=1) Buffers: shared hit=23629060 read=676672 dirtied=8 written=13717 -> Nested Loop (cost=2840392.35..3509449.32 rows=138 width=24) (actual time=126436.103..158523.759 rows=3245664 loops=1) Buffers: shared hit=10648631 read=656735 written=12650 -> Merge Join (cost=2840392.35..3509409.13 rows=138 width=28) (actual time=126436.063..139149.639 rows=3245664 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=894044 read=656735 written=12650 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.015..6370.276 rows=7999905 loops=1) Buffers: shared hit=285592 read=148613 written=12650 -> Sort (cost=2840392.23..2849033.97 rows=3456699 width=28) (actual time=126435.829..128631.488 rows=3245664 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 351872kB Buffers: shared hit=608452 read=508122 -> Hash Join (cost=66948.40..2464978.06 rows=3456699 width=28) (actual time=1673.948..121968.676 rows=3245664 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=608449 read=508122 -> Seq Scan on lineitem (cost=0.00..1681889.14 rows=60584314 width=24) (actual time=0.034..24207.388 rows=60044176 loops=1) Buffers: shared hit=599225 read=476821 -> Hash (cost=65522.00..65522.00 rows=114112 width=4) (actual time=1673.640..1673.640 rows=108199 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3804kB Buffers: shared hit=9221 read=31301 -> Seq Scan on part (cost=0.00..65522.00 rows=114112 width=4) (actual time=0.040..1605.498 rows=108199 loops=1) Filter: ((p_name)::text ~~ '%chartreuse%'::text) Rows Removed by Filter: 1891801 Buffers: shared hit=9221 read=31301 -> 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=3245664) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9754587 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.97 rows=1 width=8) (actual time=0.017..0.017 rows=1 loops=3245664) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3245664 Buffers: shared hit=12980429 read=19937 dirtied=8 written=1067 -> 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=3245664) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6491328 Total runtime: 260906.667 ms (44 rows) COMMIT; COMMIT