BEGIN; BEGIN create or replace view revenue1 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-01-01' and l_shipdate < date'1994-01-01' + interval '90 days' group by l_suppkey; CREATE VIEW EXPLAIN (ANALYZE, BUFFERS) select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier, revenue1 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue1 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2368187.19..2373284.01 rows=3708 width=79) (actual time=21559.594..21559.600 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue1.supplier_no) Buffers: shared hit=850750 read=472303 dirtied=130 written=6415 InitPlan 1 (returns $0) -> Aggregate (cost=1175585.41..1175585.42 rows=1 width=8) (actual time=10526.600..10526.600 rows=1 loops=1) Buffers: shared hit=403092 read=258128 written=93 -> HashAggregate (cost=1175501.98..1175539.06 rows=3708 width=12) (actual time=10484.512..10516.451 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=403092 read=258128 written=93 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47367.45..1153106.97 rows=2239501 width=12) (actual time=2481.298..8644.303 rows=2242133 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655090 Buffers: shared hit=403092 read=258128 written=93 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46807.58 rows=2239501 width=0) (actual time=2028.927..2028.927 rows=2257759 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6130 written=2 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.029..9.387 rows=21986 loops=1) Buffers: shared hit=613 -> Sort (cost=1192601.48..1192610.75 rows=3708 width=12) (actual time=21548.036..21548.039 rows=1 loops=1) Sort Key: revenue1.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=850137 read=472303 dirtied=130 written=6415 -> Subquery Scan on revenue1 (cost=1192298.23..1192381.66 rows=3708 width=12) (actual time=21521.047..21548.000 rows=1 loops=1) Buffers: shared hit=850137 read=472303 dirtied=130 written=6415 -> HashAggregate (cost=1192298.23..1192344.58 rows=3708 width=12) (actual time=21521.045..21547.996 rows=1 loops=1) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=850137 read=472303 dirtied=130 written=6415 -> Bitmap Heap Scan on lineitem (cost=47367.45..1153106.97 rows=2239501 width=12) (actual time=1261.420..7904.074 rows=2242133 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655090 Buffers: shared hit=447045 read=214175 dirtied=130 written=6322 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46807.58 rows=2239501 width=0) (actual time=989.823..989.823 rows=2256498 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=568 read=5562 written=359 Planning time: 2.685 ms Execution time: 21570.605 ms (38 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT