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=3471372.64..3471377.29 rows=133 width=46) (actual time=346059.971..349502.588 rows=175 loops=1) Buffers: shared hit=30108179 read=816327 dirtied=29 written=2409 -> Sort (cost=3471372.64..3471372.97 rows=133 width=46) (actual time=346034.461..347074.308 rows=3260784 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556852kB Buffers: shared hit=30108179 read=816327 dirtied=29 written=2409 -> Nested Loop (cost=2803121.80..3471367.95 rows=133 width=46) (actual time=143465.769..323651.168 rows=3260784 loops=1) Buffers: shared hit=30108171 read=816327 dirtied=29 written=2409 -> Nested Loop (cost=2803121.80..3471330.02 rows=133 width=24) (actual time=143465.650..293726.838 rows=3260784 loops=1) Buffers: shared hit=23586603 read=816327 dirtied=29 written=2409 -> Nested Loop (cost=2803121.80..3471070.47 rows=133 width=24) (actual time=143465.594..196363.456 rows=3260784 loops=1) Buffers: shared hit=10710306 read=631601 written=1506 -> Merge Join (cost=2803121.80..3471031.74 rows=133 width=28) (actual time=143465.477..160168.258 rows=3260784 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=910681 read=631601 written=1506 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.025..8603.588 rows=7999925 loops=1) Buffers: shared hit=281175 read=153033 written=1499 -> Sort (cost=2803121.24..2811393.90 rows=3309064 width=28) (actual time=143465.403..146764.692 rows=3260784 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353053kB Buffers: shared hit=629506 read=478568 written=7 -> Hash Join (cost=66898.35..2444782.84 rows=3309064 width=28) (actual time=1495.414..129185.667 rows=3260784 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=629503 read=478568 written=7 -> Seq Scan on lineitem (cost=0.00..1668603.81 rows=60105781 width=24) (actual time=16.960..25317.576 rows=60045603 loops=1) Buffers: shared hit=623019 read=444527 written=7 -> Hash (cost=65522.00..65522.00 rows=110108 width=4) (actual time=1478.245..1478.245 rows=108577 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3818kB Buffers: shared hit=6481 read=34041 -> Seq Scan on part (cost=0.00..65522.00 rows=110108 width=4) (actual time=0.027..1419.470 rows=108577 loops=1) Filter: ((p_name)::text ~~ '%lace%'::text) Rows Removed by Filter: 1891423 Buffers: shared hit=6481 read=34041 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.009..0.010 rows=1 loops=3260784) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9799625 -> Index Scan using pk_orders on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.028..0.029 rows=1 loops=3260784) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12876297 read=184726 dirtied=29 written=903 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.006..0.007 rows=1 loops=3260784) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6521568 Total runtime: 349649.609 ms (43 rows) COMMIT; COMMIT