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 '%dark%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3340203.22..3340207.25 rows=115 width=46) (actual time=269805.237..273272.862 rows=175 loops=1) Buffers: shared hit=30152286 read=701295 dirtied=133 written=1626 -> Sort (cost=3340203.22..3340203.51 rows=115 width=46) (actual time=269792.026..270828.844 rows=3252754 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 555723kB Buffers: shared hit=30152286 read=701295 dirtied=133 written=1626 -> Nested Loop (cost=2675157.69..3340199.28 rows=115 width=46) (actual time=125328.580..249440.482 rows=3252754 loops=1) Buffers: shared hit=30152278 read=701295 dirtied=133 written=1626 -> Nested Loop (cost=2675157.69..3340166.49 rows=115 width=24) (actual time=125328.497..229472.561 rows=3252754 loops=1) Buffers: shared hit=23646770 read=701295 dirtied=133 written=1626 -> Nested Loop (cost=2675157.69..3339942.07 rows=115 width=24) (actual time=125328.391..161800.298 rows=3252754 loops=1) Buffers: shared hit=10795431 read=523673 written=1132 -> Merge Join (cost=2675157.69..3339908.29 rows=116 width=28) (actual time=125328.331..139555.718 rows=3252754 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1018610 read=523673 written=1132 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.022..6693.352 rows=7999981 loops=1) Buffers: shared hit=267596 read=166613 written=1129 -> Sort (cost=2675157.59..2682377.34 rows=2887900 width=28) (actual time=125328.206..128422.211 rows=3252754 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352426kB Buffers: shared hit=751014 read=357060 written=3 -> Hash Join (cost=66723.18..2365262.97 rows=2887900 width=28) (actual time=1403.634..119629.363 rows=3252754 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=751011 read=357060 written=3 -> Seq Scan on lineitem (cost=0.00..1668603.40 rows=60105740 width=24) (actual time=0.050..22849.272 rows=60045603 loops=1) Buffers: shared hit=711486 read=356060 written=3 -> Hash (cost=65522.00..65522.00 rows=96094 width=4) (actual time=1403.086..1403.086 rows=108402 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3812kB Buffers: shared hit=39522 read=1000 -> Seq Scan on part (cost=0.00..65522.00 rows=96094 width=4) (actual time=0.027..1336.129 rows=108402 loops=1) Filter: ((p_name)::text ~~ '%dark%'::text) Rows Removed by Filter: 1891598 Buffers: shared hit=39522 read=1000 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.005..0.006 rows=1 loops=3252754) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9776821 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.019..0.020 rows=1 loops=3252754) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3252754 Buffers: shared hit=12851339 read=177622 dirtied=133 written=494 -> 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=3252754) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6505508 Total runtime: 273421.599 ms (44 rows) COMMIT; COMMIT