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 '%grey%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3501397.01..3501401.87 rows=139 width=46) (actual time=292867.746..296517.956 rows=175 loops=1) Buffers: shared hit=30071444 read=835524 written=1562 -> Sort (cost=3501397.01..3501397.35 rows=139 width=46) (actual time=292855.209..293925.775 rows=3258141 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556481kB Buffers: shared hit=30071444 read=835524 written=1562 -> Nested Loop (cost=2832097.99..3501392.06 rows=139 width=46) (actual time=140158.011..271977.210 rows=3258141 loops=1) Buffers: shared hit=30071436 read=835524 written=1562 -> Nested Loop (cost=2832097.99..3501352.41 rows=139 width=24) (actual time=140157.927..249870.392 rows=3258141 loops=1) Buffers: shared hit=23555154 read=835524 written=1562 -> Nested Loop (cost=2832097.99..3501078.88 rows=139 width=24) (actual time=140157.865..180833.613 rows=3258141 loops=1) Buffers: shared hit=10510011 read=830172 written=1550 -> Merge Join (cost=2832097.99..3501038.40 rows=139 width=28) (actual time=140157.815..154449.700 rows=3258141 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=717420 read=830172 written=1550 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.015..7433.402 rows=7999933 loops=1) Buffers: shared hit=298165 read=136043 written=1546 -> Sort (cost=2832097.43..2840713.56 rows=3446453 width=28) (actual time=140157.588..142546.710 rows=3258141 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352847kB Buffers: shared hit=419255 read=694129 written=4 -> Hash Join (cost=66948.40..2457869.82 rows=3446453 width=28) (actual time=1516.949..135448.584 rows=3258141 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=419252 read=694129 written=4 -> Seq Scan on lineitem (cost=0.00..1676903.48 rows=60404748 width=24) (actual time=0.031..31764.124 rows=60045310 loops=1) Buffers: shared hit=419247 read=653609 written=4 -> Hash (cost=65522.00..65522.00 rows=114112 width=4) (actual time=1516.621..1516.621 rows=108577 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3818kB Buffers: shared hit=2 read=40520 -> Seq Scan on part (cost=0.00..65522.00 rows=114112 width=4) (actual time=0.031..1451.457 rows=108577 loops=1) Filter: ((p_name)::text ~~ '%grey%'::text) Rows Removed by Filter: 1891423 Buffers: shared hit=2 read=40520 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.007..0.007 rows=1 loops=3258141) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9792591 -> Index Scan using pk_orders on orders (cost=0.00..1.96 rows=1 width=8) (actual time=0.020..0.020 rows=1 loops=3258141) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=13045143 read=5352 written=12 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.004..0.005 rows=1 loops=3258141) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6516282 Total runtime: 296636.364 ms (43 rows) COMMIT; COMMIT