BEGIN; BEGIN create or replace view revenue17 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-11-01' and l_shipdate < date'1993-11-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, revenue17 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue17 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2364584.47..2369680.55 rows=3659 width=79) (actual time=20439.937..20439.940 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue17.supplier_no) Buffers: shared hit=550513 read=772758 dirtied=563 written=209 InitPlan 1 (returns $0) -> Aggregate (cost=1173895.06..1173895.07 rows=1 width=8) (actual time=9905.665..9905.665 rows=1 loops=1) Buffers: shared hit=192768 read=468757 written=209 -> HashAggregate (cost=1173812.73..1173849.32 rows=3659 width=12) (actual time=9861.025..9895.467 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=192768 read=468757 written=209 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=46756.46..1151709.42 rows=2210331 width=12) (actual time=1667.998..8014.351 rows=2244655 loops=1) Recheck Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655396 Buffers: shared hit=192768 read=468757 written=209 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46203.88 rows=2210331 width=0) (actual time=1285.238..1285.238 rows=2255469 loops=1) Index Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.033..2.885 rows=7917 loops=1) Buffers: shared hit=221 -> Sort (cost=1190689.10..1190698.25 rows=3659 width=12) (actual time=20436.149..20436.149 rows=1 loops=1) Sort Key: revenue17.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=550292 read=772758 dirtied=563 written=209 -> Subquery Scan on revenue17 (cost=1190390.22..1190472.54 rows=3659 width=12) (actual time=20431.289..20436.112 rows=1 loops=1) Buffers: shared hit=550292 read=772758 dirtied=563 written=209 -> HashAggregate (cost=1190390.22..1190435.95 rows=3659 width=12) (actual time=20431.288..20436.109 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=550292 read=772758 dirtied=563 written=209 -> Bitmap Heap Scan on lineitem (cost=46756.46..1151709.42 rows=2210331 width=12) (actual time=1875.884..8575.968 rows=2244655 loops=1) Recheck Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655396 Buffers: shared hit=357524 read=304001 dirtied=563 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46203.88 rows=2210331 width=0) (actual time=1468.708..1468.708 rows=2255469 loops=1) Index Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 Planning time: 3.157 ms Execution time: 20450.230 ms (38 rows) drop view revenue17; DROP VIEW COMMIT; COMMIT