BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-08-01' and l_shipdate < date'1994-08-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363039.17..2368136.98 rows=3757 width=79) (actual time=33238.838..33238.844 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=548942 read=772086 written=220 InitPlan 1 (returns $0) -> Aggregate (cost=1172944.13..1172944.14 rows=1 width=8) (actual time=15093.811..15093.811 rows=1 loops=1) Buffers: shared hit=310041 read=349817 written=15 -> HashAggregate (cost=1172859.59..1172897.16 rows=3757 width=12) (actual time=15000.307..15075.453 rows=100000 loops=1) Buffers: shared hit=310041 read=349817 written=15 -> Bitmap Heap Scan on lineitem (cost=47825.52..1150289.16 rows=2257043 width=12) (actual time=2018.497..10962.511 rows=2247699 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=310041 read=349817 written=15 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47261.26 rows=2257043 width=0) (actual time=1676.396..1676.396 rows=2252299 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.087..20.838 rows=47970 loops=1) Buffers: shared hit=1311 -> Sort (cost=1190095.03..1190104.42 rows=3757 width=12) (actual time=33212.987..33212.990 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=547631 read=772086 written=220 -> Subquery Scan on revenue8 (cost=1189787.42..1189871.95 rows=3757 width=12) (actual time=33210.564..33212.954 rows=1 loops=1) Buffers: shared hit=547631 read=772086 written=220 -> HashAggregate (cost=1189787.42..1189834.38 rows=3757 width=12) (actual time=33210.561..33212.950 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=547631 read=772086 written=220 -> Bitmap Heap Scan on lineitem (cost=47825.52..1150289.16 rows=2257043 width=12) (actual time=2428.104..13922.146 rows=2247699 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=237590 read=422269 written=205 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47261.26 rows=2257043 width=0) (actual time=2061.570..2061.570 rows=2252299 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6139 Total runtime: 33250.684 ms (33 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT