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 '%turquoise%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3234992.28..3234995.82 rows=101 width=46) (actual time=269136.360..272594.377 rows=175 loops=1) Buffers: shared hit=30028081 read=821794 dirtied=117 written=18156 -> Sort (cost=3234992.28..3234992.53 rows=101 width=46) (actual time=269123.360..270109.323 rows=3251609 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 555562kB Buffers: shared hit=30028081 read=821794 dirtied=117 written=18156 -> Nested Loop (cost=2572554.79..3234988.92 rows=101 width=46) (actual time=123259.494..247470.283 rows=3251609 loops=1) Buffers: shared hit=30028073 read=821794 dirtied=117 written=18156 -> Nested Loop (cost=2572554.79..3234960.11 rows=101 width=24) (actual time=123259.408..227883.849 rows=3251609 loops=1) Buffers: shared hit=23524855 read=821794 dirtied=117 written=18156 -> Nested Loop (cost=2572554.79..3234760.69 rows=101 width=24) (actual time=123259.325..159290.783 rows=3251609 loops=1) Buffers: shared hit=10852614 read=469791 written=8242 -> Merge Join (cost=2572554.79..3234730.99 rows=102 width=28) (actual time=123259.270..136036.337 rows=3251609 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1079922 read=469791 written=8242 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.017..6138.152 rows=7999965 loops=1) Buffers: shared hit=330709 read=103500 written=8230 -> Sort (cost=2572554.78..2578916.08 rows=2544517 width=28) (actual time=123259.134..125579.889 rows=3251609 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352336kB Buffers: shared hit=749213 read=366291 written=12 -> Hash Join (cost=66573.02..2301831.40 rows=2544517 width=28) (actual time=1277.023..118883.906 rows=3251609 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=749210 read=366291 written=12 -> Seq Scan on lineitem (cost=0.00..1680222.51 rows=60524651 width=24) (actual time=0.043..20985.647 rows=60044082 loops=1) Buffers: shared hit=708685 read=366291 written=12 -> Hash (cost=65522.00..65522.00 rows=84082 width=4) (actual time=1276.761..1276.761 rows=108348 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3810kB Buffers: shared hit=40522 -> Seq Scan on part (cost=0.00..65522.00 rows=84082 width=4) (actual time=0.031..1213.187 rows=108348 loops=1) Filter: ((p_name)::text ~~ '%turquoise%'::text) Rows Removed by Filter: 1891652 Buffers: shared hit=40522 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=3251609) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9772692 -> 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=3251609) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12672241 read=352003 dirtied=117 written=9914 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.003..0.004 rows=1 loops=3251609) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6503218 Total runtime: 272682.882 ms (43 rows) COMMIT; COMMIT