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 '%drab%' ) as profit group by nation, o_year order by nation, o_year desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=3385602.00..3385606.44 rows=127 width=46) (actual time=246915.370..250423.208 rows=175 loops=1) Buffers: shared hit=30472577 read=611751 dirtied=16 written=1633 -> Sort (cost=3385602.00..3385602.31 rows=127 width=46) (actual time=246901.779..248139.737 rows=3278228 loops=1) Sort Key: nation.n_name, (date_part('year'::text, (orders.o_orderdate)::timestamp without time zone)) Sort Method: quicksort Memory: 559305kB Buffers: shared hit=30472577 read=611751 dirtied=16 written=1633 -> Nested Loop (cost=2718216.68..3385597.56 rows=127 width=46) (actual time=115698.528..224778.934 rows=3278228 loops=1) Buffers: shared hit=30472569 read=611751 dirtied=16 written=1633 -> Nested Loop (cost=2718216.68..3385561.34 rows=127 width=24) (actual time=115698.436..207685.954 rows=3278228 loops=1) Buffers: shared hit=23916113 read=611751 dirtied=16 written=1633 -> Nested Loop (cost=2718216.68..3385312.66 rows=127 width=24) (actual time=115698.382..147526.022 rows=3278228 loops=1) Buffers: shared hit=10970815 read=426073 written=181 -> Merge Join (cost=2718216.68..3385275.39 rows=128 width=28) (actual time=115698.275..127631.956 rows=3278228 loops=1) Merge Cond: ((partsupp.ps_partkey = lineitem.l_partkey) AND (partsupp.ps_suppkey = lineitem.l_suppkey)) Buffers: shared hit=1118326 read=426073 written=181 -> Index Scan using pk_partsupp on partsupp (cost=0.00..603091.33 rows=8000000 width=12) (actual time=0.014..5393.556 rows=7999889 loops=1) Buffers: shared hit=366717 read=67488 written=178 -> Sort (cost=2718216.67..2726205.38 rows=3195484 width=28) (actual time=115698.133..118214.266 rows=3278228 loops=1) Sort Key: part.p_partkey, lineitem.l_suppkey Sort Method: quicksort Memory: 354416kB Buffers: shared hit=751609 read=358585 written=3 -> Hash Join (cost=66848.46..2372982.92 rows=3195484 width=28) (actual time=1721.515..111844.619 rows=3278228 loops=1) Hash Cond: (lineitem.l_partkey = part.p_partkey) Buffers: shared hit=751606 read=358585 written=3 -> Seq Scan on lineitem (cost=0.00..1671922.81 rows=60225681 width=24) (actual time=0.045..21558.633 rows=60045303 loops=1) Buffers: shared hit=742172 read=327494 written=3 -> Hash (cost=65522.00..65522.00 rows=106117 width=4) (actual time=1721.267..1721.267 rows=109161 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 3838kB Buffers: shared hit=9431 read=31091 -> Seq Scan on part (cost=0.00..65522.00 rows=106117 width=4) (actual time=0.034..1639.536 rows=109161 loops=1) Filter: ((p_name)::text ~~ '%drab%'::text) Rows Removed by Filter: 1890839 Buffers: shared hit=9431 read=31091 -> 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=3278228) Index Cond: (s_suppkey = lineitem.l_suppkey) Buffers: shared hit=9852489 -> Index Scan using pk_orders on orders (cost=0.00..1.95 rows=1 width=8) (actual time=0.017..0.017 rows=1 loops=3278228) Index Cond: (o_orderkey = lineitem.l_orderkey) Buffers: shared hit=12945298 read=185678 dirtied=16 written=1452 -> 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=3278228) Index Cond: (n_nationkey = supplier.s_nationkey) Buffers: shared hit=6556456 Total runtime: 250566.677 ms (43 rows) COMMIT; COMMIT