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 '%coral%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3523174.98..3523179.99 rows=143 width=46) (actual time=655567.273..659098.207 rows=175 loops=1) Buffers: shared hit=30497024 read=489074 dirtied=11 written=1741 -> Sort (cost=3523174.98..3523175.34 rows=143 width=46) (actual time=655552.406..656520.519 rows=3266801 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 557698kB Buffers: shared hit=30497024 read=489074 dirtied=11 written=1741 -> Nested Loop (cost=2852904.45..3523169.87 rows=143 width=46) (actual time=197458.307..633941.045 rows=3266801 loops=1) Buffers: shared hit=30497016 read=489074 dirtied=11 written=1741 -> Nested Loop (cost=2852904.45..3523129.08 rows=143 width=24) (actual time=197456.894..529488.921 rows=3266801 loops=1) Buffers: shared hit=23963414 read=489074 dirtied=11 written=1741 -> Nested Loop (cost=2852904.45..3522846.73 rows=143 width=24) (actual time=197456.796..324362.813 rows=3266801 loops=1) Buffers: shared hit=11018874 read=348768 dirtied=4 written=165 -> Merge Join (cost=2852904.45..3522805.09 rows=143 width=28) (actual time=197456.222..217207.659 rows=3266801 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1200945 read=348768 dirtied=4 written=165 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.29 rows=8000000 width=12) (actual time=0.027..11146.432 rows=7999993 loops=1) Buffers: shared hit=417200 read=17009 written=160 -> Sort (cost=2852904.42..2861840.42 rows=3574400 width=28) (actual time=197456.091..200763.833 rows=3266801 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 353523kB Buffers: shared hit=783745 read=331759 dirtied=4 written=5 -> Hash Join (cost=66998.45..2463844.04 rows=3574400 width=28) (actual time=2577.901..193159.556 rows=3266801 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=783742 read=331759 dirtied=4 written=5 -> Seq Scan on lineitem (cost=0.00..1680211.57 rows=60523557 width=24) (actual time=0.034..62246.456 rows=60044082 loops=1) Buffers: shared hit=749756 read=325220 dirtied=4 written=5 -> Hash (cost=65522.00..65522.00 rows=118116 width=4) (actual time=2577.628..2577.628 rows=108789 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3825kB Buffers: shared hit=33983 read=6539 -> Seq Scan on part (cost=0.00..65522.00 rows=118116 width=4) (actual time=0.022..2500.376 rows=108789 loops=1) Filter: ((p_name)::text ~~ '%coral%'::text) Rows Removed by Filter: 1891211 Buffers: shared hit=33983 read=6539 -> Index Scan using pk_supplier on supplier (cost=0.00..0.28 rows=1 width=8) (actual time=0.031..0.031 rows=1 loops=3266801) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9817929 -> Index Scan using pk_orders on orders (cost=0.00..1.96 rows=1 width=8) (actual time=0.061..0.061 rows=1 loops=3266801) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12944540 read=140306 dirtied=7 written=1576 -> Index Scan using pk_nation on nation (cost=0.00..0.27 rows=1 width=30) (actual time=0.029..0.029 rows=1 loops=3266801) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6533602 Total runtime: 659211.701 ms (43 rows) COMMIT; COMMIT