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 '%lawn%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3240041.41..3240044.98 rows=102 width=46) (actual time=704922.505..708970.519 rows=175 loops=1) Buffers: shared hit=30277782 read=650024 dirtied=16 written=2163 -> Sort (cost=3240041.41..3240041.67 rows=102 width=46) (actual time=704905.119..706141.668 rows=3260082 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556754kB Buffers: shared hit=30277782 read=650024 dirtied=16 written=2163 -> Nested Loop (cost=2577563.31..3240038.01 rows=102 width=46) (actual time=188669.847..681968.479 rows=3260082 loops=1) Buffers: shared hit=30277774 read=650024 dirtied=16 written=2163 -> Nested Loop (cost=2577563.31..3240008.92 rows=102 width=24) (actual time=188669.756..561067.572 rows=3260082 loops=1) Buffers: shared hit=23757610 read=650024 dirtied=16 written=2163 -> Nested Loop (cost=2577563.31..3239806.85 rows=102 width=24) (actual time=188669.660..334504.404 rows=3260082 loops=1) Buffers: shared hit=10812088 read=537600 written=865 -> Merge Join (cost=2577563.31..3239777.15 rows=102 width=28) (actual time=188669.598..213234.323 rows=3260082 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1014257 read=537600 written=865 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.044..16022.950 rows=7999993 loops=1) Buffers: shared hit=350935 read=83274 written=810 -> Sort (cost=2577563.28..2583937.15 rows=2549546 width=28) (actual time=188669.465..191651.426 rows=3260082 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352998kB Buffers: shared hit=663322 read=454326 written=55 -> Hash Join (cost=66573.02..2306268.53 rows=2549546 width=28) (actual time=4075.545..184576.256 rows=3260082 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=663319 read=454326 written=55 -> Seq Scan on lineitem (cost=0.00..1683562.69 rows=60644269 width=24) (actual time=0.027..62181.735 rows=60044872 loops=1) Buffers: shared hit=662787 read=414333 written=2 -> Hash (cost=65522.00..65522.00 rows=84082 width=4) (actual time=4075.206..4075.206 rows=108565 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3817kB Buffers: shared hit=529 read=39993 written=53 -> Seq Scan on part (cost=0.00..65522.00 rows=84082 width=4) (actual time=0.030..3987.881 rows=108565 loops=1) Filter: ((p_name)::text ~~ '%lawn%'::text) Rows Removed by Filter: 1891435 Buffers: shared hit=529 read=39993 written=53 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.035..0.036 rows=1 loops=3260082) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9797831 -> Index Scan using pk_orders on orders (cost=0.00..1.97 rows=1 width=8) (actual time=0.068..0.068 rows=1 loops=3260082) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12945522 read=112424 dirtied=16 written=1298 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.034..0.034 rows=1 loops=3260082) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6520164 Total runtime: 709108.474 ms (43 rows) COMMIT; COMMIT