BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-12-01' and l_shipdate < date'1996-12-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2392557.18..2397655.46 rows=3788 width=79) (actual time=35229.849..35229.851 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=295294 read=1040873 written=912 InitPlan 1 (returns $0) -> Aggregate (cost=1187530.63..1187530.64 rows=1 width=8) (actual time=16415.091..16415.091 rows=1 loops=1) Buffers: shared hit=180440 read=487491 written=26 -> HashAggregate (cost=1187445.40..1187483.28 rows=3788 width=12) (actual time=16345.662..16402.462 rows=100000 loops=1) Buffers: shared hit=180440 read=487491 written=26 -> Bitmap Heap Scan on lineitem (cost=48494.20..1164417.72 rows=2302768 width=12) (actual time=2013.618..12425.406 rows=2246387 loops=1) Recheck Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=180440 read=487491 written=26 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47918.51 rows=2302768 width=0) (actual time=1510.724..1510.724 rows=2277671 loops=1) Index Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared read=6136 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.121..5.339 rows=10906 loops=1) Buffers: shared hit=303 read=1 -> Sort (cost=1205026.54..1205036.01 rows=3788 width=12) (actual time=35223.367..35223.367 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=294991 read=1040872 written=912 -> Subquery Scan on revenue7 (cost=1204716.16..1204801.39 rows=3788 width=12) (actual time=35203.566..35223.331 rows=1 loops=1) Buffers: shared hit=294991 read=1040872 written=912 -> HashAggregate (cost=1204716.16..1204763.51 rows=3788 width=12) (actual time=35203.563..35223.326 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=294991 read=1040872 written=912 -> Bitmap Heap Scan on lineitem (cost=48494.20..1164417.72 rows=2302768 width=12) (actual time=2452.024..14777.359 rows=2246387 loops=1) Recheck Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=114551 read=553381 written=886 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47918.51 rows=2302768 width=0) (actual time=2026.823..2026.823 rows=2277671 loops=1) Index Cond: ((l_shipdate >= '1996-12-01'::date) AND (l_shipdate < '1997-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6134 Total runtime: 35250.860 ms (33 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT