BEGIN; BEGIN create or replace view revenue9 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-04-01' and l_shipdate < date'1993-04-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, revenue9 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue9 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2373593.05..2378691.02 rows=3767 width=79) (actual time=35229.412..35229.418 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=710220 read=616521 written=14 InitPlan 1 (returns $0) -> Aggregate (cost=1178136.09..1178136.10 rows=1 width=8) (actual time=17495.287..17495.287 rows=1 loops=1) Buffers: shared hit=317488 read=345631 written=10 -> HashAggregate (cost=1178051.33..1178089.00 rows=3767 width=12) (actual time=17427.567..17478.268 rows=100000 loops=1) Buffers: shared hit=317488 read=345631 written=10 -> Bitmap Heap Scan on lineitem (cost=48204.90..1155255.16 rows=2279617 width=12) (actual time=2400.778..13554.842 rows=2250107 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=317488 read=345631 written=10 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47635.00 rows=2279617 width=0) (actual time=2054.033..2054.033 rows=2263423 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6143 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.057..12.968 rows=17858 loops=1) Buffers: shared hit=502 -> Sort (cost=1195456.96..1195466.38 rows=3767 width=12) (actual time=35213.402..35213.405 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=709718 read=616521 written=14 -> Subquery Scan on revenue9 (cost=1195148.46..1195233.21 rows=3767 width=12) (actual time=35202.798..35213.356 rows=1 loops=1) Buffers: shared hit=709718 read=616521 written=14 -> HashAggregate (cost=1195148.46..1195195.54 rows=3767 width=12) (actual time=35202.795..35213.350 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=709718 read=616521 written=14 -> Bitmap Heap Scan on lineitem (cost=48204.90..1155255.16 rows=2279617 width=12) (actual time=1930.975..13201.780 rows=2250107 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=392230 read=270890 written=4 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47635.00 rows=2279617 width=0) (actual time=1615.385..1615.385 rows=2263423 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6143 Total runtime: 35243.656 ms (33 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT