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 '%olive%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3396254.56..3396258.97 rows=126 width=46) (actual time=249282.788..252681.210 rows=175 loops=1) Buffers: shared hit=29792388 read=993595 dirtied=40 written=6149 -> Sort (cost=3396254.56..3396254.88 rows=126 width=46) (actual time=249238.865..250227.206 rows=3244308 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 554535kB Buffers: shared hit=29792388 read=993595 dirtied=40 written=6149 -> Nested Loop (cost=2729161.82..3396250.16 rows=126 width=46) (actual time=116900.584..226478.326 rows=3244308 loops=1) Buffers: shared hit=29792380 read=993595 dirtied=40 written=6149 -> Nested Loop (cost=2729161.82..3396214.23 rows=126 width=24) (actual time=116900.521..210018.066 rows=3244308 loops=1) Buffers: shared hit=23303764 read=993595 dirtied=40 written=6149 -> Nested Loop (cost=2729161.82..3395964.61 rows=126 width=24) (actual time=116900.426..147930.529 rows=3244308 loops=1) Buffers: shared hit=10515257 read=787233 written=1828 -> Merge Join (cost=2729161.82..3395927.92 rows=126 width=28) (actual time=116900.380..129000.518 rows=3244308 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=764617 read=787233 written=1828 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.008..5654.141 rows=7999861 loops=1) Buffers: shared hit=317147 read=117055 written=1826 -> Sort (cost=2729161.71..2737053.27 rows=3156622 width=28) (actual time=116900.244..119303.706 rows=3244308 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 351766kB Buffers: shared hit=447470 read=670178 written=2 -> Hash Join (cost=66823.27..2388405.16 rows=3156622 width=28) (actual time=1808.694..111765.451 rows=3244308 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=447467 read=670178 written=2 -> Seq Scan on lineitem (cost=0.00..1683567.83 rows=60644783 width=24) (actual time=0.027..22994.715 rows=60044872 loops=1) Buffers: shared hit=424761 read=652359 written=2 -> Hash (cost=65522.00..65522.00 rows=104102 width=4) (actual time=1808.540..1808.540 rows=108018 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3798kB Buffers: shared hit=22703 read=17819 -> Seq Scan on part (cost=0.00..65522.00 rows=104102 width=4) (actual time=0.020..1740.550 rows=108018 loops=1) Filter: ((p_name)::text ~~ '%olive%'::text) Rows Removed by Filter: 1891982 Buffers: shared hit=22703 read=17819 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.004..0.005 rows=1 loops=3244308) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9750640 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.97 rows=1 width=8) (actual time=0.018..0.018 rows=1 loops=3244308) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3244308 Buffers: shared hit=12788507 read=206362 dirtied=40 written=4321 -> 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=3244308) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6488616 Total runtime: 252794.639 ms (44 rows) COMMIT; COMMIT