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=1179134.21..1179138.69 rows=128 width=46) (actual time=106301.102..109119.029 rows=175 loops=1) Group Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Buffers: shared hit=35701523 read=2163334 dirtied=11284 written=25382 -> Sort (cost=1179134.21..1179134.53 rows=128 width=46) (actual time=106291.264..107117.019 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=35701523 read=2163334 dirtied=11284 written=25382 -> Hash Join (cost=66851.17..1179129.73 rows=128 width=46) (actual time=865.504..92654.248 rows=3252754 loops=1) Hash Cond: (supplier.s_nationkey = nation.n_nationkey) Buffers: shared hit=35701515 read=2163334 dirtied=11284 written=25382 -> Nested Loop (cost=66849.60..1179125.76 rows=128 width=24) (actual time=865.437..89898.978 rows=3252754 loops=1) Buffers: shared hit=35701511 read=2163334 dirtied=11284 written=25382 -> Nested Loop (cost=66849.31..1179084.79 rows=127 width=28) (actual time=865.426..78658.269 rows=3252754 loops=1) Buffers: shared hit=25924700 read=2163334 dirtied=11284 written=25382 -> Nested Loop (cost=66848.88..1179023.24 rows=127 width=28) (actual time=865.401..37283.224 rows=3252754 loops=1) Buffers: shared hit=13517022 read=1542161 dirtied=11075 written=18555 -> Hash Join (cost=66848.31..352030.79 rows=422448 width=16) (actual time=865.262..5437.412 rows=433608 loops=1) Hash Cond: (partsupp.ps_partkey = part.p_partkey) Buffers: shared hit=71805 read=139675 written=1849 -> Seq Scan on partsupp (cost=0.00..250958.00 rows=8000000 width=12) (actual time=0.004..2581.253 rows=8000000 loops=1) Buffers: shared hit=39111 read=131847 written=1809 -> Hash (cost=65522.00..65522.00 rows=106105 width=4) (actual time=864.628..864.628 rows=108402 loops=1) Buckets: 131072 Batches: 1 Memory Usage: 4836kB Buffers: shared hit=32694 read=7828 written=40 -> Seq Scan on part (cost=0.00..65522.00 rows=106105 width=4) (actual time=0.016..827.674 rows=108402 loops=1) Filter: ((p_name)::text ~~ '%dark%'::text) Rows Removed by Filter: 1891598 Buffers: shared hit=32694 read=7828 written=40 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.56..1.95 rows=1 width=24) (actual time=0.015..0.071 rows=8 loops=433608) Index Cond: (l_partkey = partsupp.ps_partkey) Filter: (partsupp.ps_suppkey = l_suppkey) Rows Removed by Filter: 23 Buffers: shared hit=13445217 read=1402486 dirtied=11075 written=16706 -> Index Scan using pk_orders on orders (cost=0.43..0.47 rows=1 width=8) (actual time=0.012..0.012 rows=1 loops=3252754) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12407678 read=621173 dirtied=209 written=6827 -> Index Scan using pk_supplier on supplier (cost=0.29..0.31 rows=1 width=8) (actual time=0.002..0.003 rows=1 loops=3252754) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9776811 -> Hash (cost=1.25..1.25 rows=25 width=30) (actual time=0.020..0.020 rows=25 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 10kB Buffers: shared hit=1 -> Seq Scan on nation (cost=0.00..1.25 rows=25 width=30) (actual time=0.005..0.011 rows=25 loops=1) Buffers: shared hit=1 Planning time: 31.791 ms Execution time: 109177.799 ms (46 rows) COMMIT; COMMIT