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 '%lace%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3377491.15..3377495.52 rows=125 width=46) (actual time=634708.299..638060.532 rows=175 loops=1) Buffers: shared hit=30130120 read=796434 dirtied=54 written=2104 -> Sort (cost=3377491.15..3377491.46 rows=125 width=46) (actual time=634694.347..635610.974 rows=3260778 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556851kB Buffers: shared hit=30130120 read=796434 dirtied=54 written=2104 -> Nested Loop (cost=2710566.89..3377486.80 rows=125 width=46) (actual time=196497.226..612227.849 rows=3260778 loops=1) Buffers: shared hit=30130112 read=796434 dirtied=54 written=2104 -> Nested Loop (cost=2710566.89..3377451.15 rows=125 width=24) (actual time=196497.143..511994.350 rows=3260778 loops=1) Buffers: shared hit=23608556 read=796434 dirtied=54 written=2104 -> Nested Loop (cost=2710566.89..3377206.39 rows=125 width=24) (actual time=196497.027..319024.951 rows=3260778 loops=1) Buffers: shared hit=10647317 read=696692 written=702 -> Merge Join (cost=2710566.89..3377169.99 rows=125 width=28) (actual time=196496.622..217853.303 rows=3260778 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=847710 read=696692 written=702 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.011..12629.250 rows=7999925 loops=1) Buffers: shared hit=388148 read=46060 written=698 -> Sort (cost=2710566.87..2718403.74 rows=3134750 width=28) (actual time=196496.587..199942.296 rows=3260778 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353053kB Buffers: shared hit=459562 read=650632 written=4 -> Hash Join (cost=66823.27..2372328.61 rows=3134750 width=28) (actual time=3266.816..191403.720 rows=3260778 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=459559 read=650632 written=4 -> Seq Scan on lineitem (cost=0.00..1671911.92 rows=60224592 width=24) (actual time=0.503..70347.582 rows=60045303 loops=1) Buffers: shared hit=435161 read=634505 written=4 -> Hash (cost=65522.00..65522.00 rows=104102 width=4) (actual time=3266.008..3266.008 rows=108577 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3818kB Buffers: shared hit=24395 read=16127 -> Seq Scan on part (cost=0.00..65522.00 rows=104102 width=4) (actual time=0.021..3181.269 rows=108577 loops=1) Filter: ((p_name)::text ~~ '%lace%'::text) Rows Removed by Filter: 1891423 Buffers: shared hit=24395 read=16127 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.029..0.030 rows=1 loops=3260778) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9799607 -> Index Scan using pk_orders on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.057..0.058 rows=1 loops=3260778) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12961239 read=99742 dirtied=54 written=1402 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.027..0.028 rows=1 loops=3260778) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6521556 Total runtime: 638185.976 ms (43 rows) COMMIT; COMMIT