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=3498615.05..3498619.88 rows=138 width=46) (actual time=258807.196..262266.310 rows=175 loops=1) Buffers: shared hit=29925181 read=922519 dirtied=1 written=4702 -> Sort (cost=3498615.05..3498615.39 rows=138 width=46) (actual time=258793.135..259818.563 rows=3251721 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 555578kB Buffers: shared hit=29925181 read=922519 dirtied=1 written=4702 -> Nested Loop (cost=2829345.05..3498610.14 rows=138 width=46) (actual time=121051.523..235359.432 rows=3251721 loops=1) Buffers: shared hit=29925173 read=922519 dirtied=1 written=4702 -> Nested Loop (cost=2829345.05..3498570.79 rows=138 width=24) (actual time=121051.453..217910.448 rows=3251721 loops=1) Buffers: shared hit=23421731 read=922519 dirtied=1 written=4702 -> Nested Loop (cost=2829345.05..3498299.67 rows=138 width=24) (actual time=121051.324..153708.035 rows=3251721 loops=1) Buffers: shared hit=10669521 read=650014 written=499 -> Merge Join (cost=2829345.05..3498259.48 rows=138 width=28) (actual time=121051.287..133864.698 rows=3251721 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=896951 read=649584 written=498 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.017..6094.404 rows=7999965 loops=1) Buffers: shared hit=286975 read=147234 written=498 -> Sort (cost=2829344.93..2837952.56 rows=3443052 width=28) (actual time=121051.177..123704.056 rows=3251721 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 352345kB Buffers: shared hit=609976 read=502350 -> Hash Join (cost=66948.40..2455511.15 rows=3443052 width=28) (actual time=2313.975..115279.095 rows=3251721 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=609973 read=502350 -> Seq Scan on lineitem (cost=0.00..1675249.40 rows=60345140 width=24) (actual time=0.034..21967.031 rows=60045826 loops=1) Buffers: shared hit=609948 read=461850 -> Hash (cost=65522.00..65522.00 rows=114112 width=4) (actual time=2313.569..2313.569 rows=108348 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3810kB Buffers: shared hit=22 read=40500 -> Seq Scan on part (cost=0.00..65522.00 rows=114112 width=4) (actual time=0.031..2225.507 rows=108348 loops=1) Filter: ((p_name)::text ~~ '%turquoise%'::text) Rows Removed by Filter: 1891652 Buffers: shared hit=22 read=40500 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=3251721) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9772570 read=430 written=1 -> Index Only Scan using orders_o_orderkey_o_orderdate_idx on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.018..0.019 rows=1 loops=3251721) Index Cond: (o_orderkey = lineitem.l_orderkey) Heap Fetches: 3251721 Buffers: shared hit=12752210 read=272505 dirtied=1 written=4203 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.003..0.003 rows=1 loops=3251721) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6503442 Total runtime: 262406.200 ms (44 rows) COMMIT; COMMIT