BEGIN; BEGIN create or replace view revenue3 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-10-01' and l_shipdate < date'1994-10-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, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2377334.31..2382431.30 rows=3719 width=79) (actual time=20391.216..20391.219 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue3.supplier_no) Buffers: shared hit=724975 read=605709 written=1085 InitPlan 1 (returns $0) -> Aggregate (cost=1180101.11..1180101.12 rows=1 width=8) (actual time=9558.704..9558.704 rows=1 loops=1) Buffers: shared hit=319454 read=345233 written=257 -> HashAggregate (cost=1180017.43..1180054.62 rows=3719 width=12) (actual time=9514.399..9547.599 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=319454 read=345233 written=257 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47600.60..1157469.10 rows=2254833 width=12) (actual time=1471.084..7596.217 rows=2241434 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658558 Buffers: shared hit=319454 read=345233 written=257 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47036.90 rows=2254833 width=0) (actual time=1140.964..1140.964 rows=2264054 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 written=1 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.046..20.016 rows=47970 loops=1) Buffers: shared hit=1310 -> Sort (cost=1197232.90..1197242.20 rows=3719 width=12) (actual time=20365.873..20365.875 rows=1 loops=1) Sort Key: revenue3.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=723665 read=605709 written=1085 -> Subquery Scan on revenue3 (cost=1196928.68..1197012.35 rows=3719 width=12) (actual time=20364.504..20365.839 rows=1 loops=1) Buffers: shared hit=723665 read=605709 written=1085 -> HashAggregate (cost=1196928.68..1196975.16 rows=3719 width=12) (actual time=20364.501..20365.835 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=723665 read=605709 written=1085 -> Bitmap Heap Scan on lineitem (cost=47600.60..1157469.10 rows=2254833 width=12) (actual time=2118.569..8788.033 rows=2241434 loops=1) Recheck Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658558 Buffers: shared hit=404211 read=260476 written=828 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47036.90 rows=2254833 width=0) (actual time=1727.540..1727.540 rows=2264054 loops=1) Index Cond: ((l_shipdate >= '1994-10-01'::date) AND (l_shipdate < '1994-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=108 read=6021 written=200 Planning time: 4.008 ms Execution time: 20406.890 ms (38 rows) drop view revenue3; DROP VIEW COMMIT; COMMIT