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 >= '1995-07-01' and l_shipdate < date'1995-07-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=2360127.33..2365224.47 rows=3712 width=79) (actual time=46687.566..46687.570 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=693612 read=627032 dirtied=184 written=40099 InitPlan 1 (returns $0) -> Aggregate (cost=1171570.23..1171570.24 rows=1 width=8) (actual time=19517.444..19517.444 rows=1 loops=1) Buffers: shared hit=413839 read=245922 written=12 -> HashAggregate (cost=1171486.71..1171523.83 rows=3712 width=12) (actual time=19413.172..19500.142 rows=100000 loops=1) Buffers: shared hit=413839 read=245922 written=12 -> Bitmap Heap Scan on lineitem (cost=47377.43..1149131.00 rows=2235571 width=12) (actual time=4882.833..15298.183 rows=2245809 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=413839 read=245922 written=12 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46818.54 rows=2235571 width=0) (actual time=4449.659..4449.659 rows=2252414 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.074..24.794 rows=40959 loops=1) Buffers: shared hit=1121 -> Sort (cost=1188557.09..1188566.37 rows=3712 width=12) (actual time=46657.339..46657.339 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=692491 read=627032 dirtied=184 written=40099 -> Subquery Scan on revenue8 (cost=1188253.49..1188337.01 rows=3712 width=12) (actual time=46650.886..46657.303 rows=1 loops=1) Buffers: shared hit=692491 read=627032 dirtied=184 written=40099 -> HashAggregate (cost=1188253.49..1188299.89 rows=3712 width=12) (actual time=46650.883..46657.296 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=692491 read=627032 dirtied=184 written=40099 -> Bitmap Heap Scan on lineitem (cost=47377.43..1149131.00 rows=2235571 width=12) (actual time=7325.522..22692.149 rows=2245809 loops=1) Recheck Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=278652 read=381110 dirtied=184 written=40087 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46818.54 rows=2235571 width=0) (actual time=6918.714..6918.714 rows=2252267 loops=1) Index Cond: ((l_shipdate >= '1995-07-01'::date) AND (l_shipdate < '1995-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=5375 read=765 Total runtime: 46718.349 ms (33 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT