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 '%papaya%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3476619.02..3476623.71 rows=134 width=46) (actual time=96454.173..99512.738 rows=175 loops=1) Buffers: shared hit=29952017 read=972307 written=7885 -> Sort (cost=3476619.02..3476619.35 rows=134 width=46) (actual time=96441.739..97298.017 rows=3260846 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 556861kB Buffers: shared hit=29952017 read=972307 written=7885 -> Nested Loop (cost=2807939.26..3476614.28 rows=134 width=46) (actual time=36661.227..80118.743 rows=3260846 loops=1) Buffers: shared hit=29952009 read=972307 written=7885 -> Nested Loop (cost=2807939.26..3476576.07 rows=134 width=24) (actual time=36661.158..74278.027 rows=3260846 loops=1) Buffers: shared hit=23430317 read=972307 written=7885 -> Nested Loop (cost=2807939.26..3476315.02 rows=134 width=24) (actual time=36660.981..51052.104 rows=3260846 loops=1) Buffers: shared hit=10663444 read=677958 written=2185 -> Merge Join (cost=2807939.26..3476275.99 rows=134 width=28) (actual time=36660.935..43500.438 rows=3260846 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=863250 read=677958 written=2185 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.011..2978.449 rows=7999905 loops=1) Buffers: shared hit=416729 read=17476 written=2185 -> Sort (cost=2807939.26..2816353.95 rows=3365879 width=28) (actual time=36660.635..38073.279 rows=3260846 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353058kB Buffers: shared hit=446521 read=660482 -> Hash Join (cost=66923.38..2443035.03 rows=3365879 width=28) (actual time=721.178..33990.512 rows=3260846 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=446518 read=660482 -> Seq Scan on lineitem (cost=0.00..1666935.17 rows=60046017 width=24) (actual time=0.005..11014.088 rows=60045669 loops=1) Buffers: shared hit=405993 read=660482 -> Hash (cost=65522.00..65522.00 rows=112110 width=4) (actual time=721.041..721.041 rows=108628 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3819kB Buffers: shared hit=40522 -> Seq Scan on part (cost=0.00..65522.00 rows=112110 width=4) (actual time=0.022..692.000 rows=108628 loops=1) Filter: ((p_name)::text ~~ '%papaya%'::text) Rows Removed by Filter: 1891372 Buffers: shared hit=40522 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=3260846) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9800194 -> Index Scan using pk_orders on orders (cost=0.00..1.94 rows=1 width=8) (actual time=0.006..0.007 rows=1 loops=3260846) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12766873 read=294349 written=5700 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.001..0.001 rows=1 loops=3260846) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6521692 Total runtime: 99549.681 ms (43 rows) COMMIT; COMMIT