BEGIN; BEGIN create or replace view revenue18 (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, revenue18 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue18 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2388248.31..2393345.94 rows=3744 width=79) (actual time=40543.878..40543.881 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue18.supplier_no) Buffers: shared hit=522146 read=812737 dirtied=652 written=226 InitPlan 1 (returns $0) -> Aggregate (cost=1185461.61..1185461.62 rows=1 width=8) (actual time=21510.498..21510.498 rows=1 loops=1) Buffers: shared hit=116930 read=550359 written=182 -> HashAggregate (cost=1185377.37..1185414.81 rows=3744 width=12) (actual time=21408.428..21492.949 rows=100000 loops=1) Buffers: shared hit=116930 read=550359 written=182 -> Bitmap Heap Scan on lineitem (cost=48048.77..1162573.53 rows=2280384 width=12) (actual time=2717.256..17086.079 rows=2246496 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=116930 read=550359 written=182 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47478.67 rows=2280384 width=0) (actual time=2295.448..2295.448 rows=2275527 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=2 read=6134 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.106..5.490 rows=10906 loops=1) Buffers: shared hit=303 read=1 -> Sort (cost=1202786.70..1202796.06 rows=3744 width=12) (actual time=40537.174..40537.174 rows=1 loops=1) Sort Key: revenue18.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=521843 read=812736 dirtied=652 written=226 -> Subquery Scan on revenue18 (cost=1202480.25..1202564.49 rows=3744 width=12) (actual time=40512.279..40537.138 rows=1 loops=1) Buffers: shared hit=521843 read=812736 dirtied=652 written=226 -> HashAggregate (cost=1202480.25..1202527.05 rows=3744 width=12) (actual time=40512.278..40537.135 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=521843 read=812736 dirtied=652 written=226 -> Bitmap Heap Scan on lineitem (cost=48048.77..1162573.53 rows=2280384 width=12) (actual time=2424.360..14870.331 rows=2246496 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=404913 read=262377 dirtied=652 written=44 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47478.67 rows=2280384 width=0) (actual time=2038.370..2038.370 rows=2275527 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=6137 Total runtime: 40560.833 ms (33 rows) drop view revenue18; DROP VIEW COMMIT; COMMIT