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 >= '1994-04-01' and l_shipdate < date'1994-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=2371807.76..2376905.46 rows=3749 width=79) (actual time=26712.450..26712.453 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=868515 read=457527 written=25707 InitPlan 1 (returns $0) -> Aggregate (cost=1177310.93..1177310.94 rows=1 width=8) (actual time=13764.706..13764.706 rows=1 loops=1) Buffers: shared hit=330978 read=331239 written=19367 -> HashAggregate (cost=1177226.57..1177264.06 rows=3749 width=12) (actual time=13698.629..13752.089 rows=100000 loops=1) Buffers: shared hit=330978 read=331239 written=19367 -> Bitmap Heap Scan on lineitem (cost=47826.07..1154608.77 rows=2261780 width=12) (actual time=1939.795..10092.169 rows=2243551 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=330978 read=331239 written=19367 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47260.63 rows=2261780 width=0) (actual time=1603.289..1603.289 rows=2261460 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1271 read=4863 written=633 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.152..24.291 rows=58899 loops=1) Buffers: shared hit=1606 read=1 -> Sort (cost=1194496.82..1194506.20 rows=3749 width=12) (actual time=26681.964..26681.964 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=866909 read=457526 written=25707 -> Subquery Scan on revenue9 (cost=1194189.92..1194274.28 rows=3749 width=12) (actual time=26663.011..26681.923 rows=1 loops=1) Buffers: shared hit=866909 read=457526 written=25707 -> HashAggregate (cost=1194189.92..1194236.79 rows=3749 width=12) (actual time=26663.008..26681.918 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=866909 read=457526 written=25707 -> Bitmap Heap Scan on lineitem (cost=47826.07..1154608.77 rows=2261780 width=12) (actual time=2616.726..9448.404 rows=2243551 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=535931 read=126287 written=6340 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47260.63 rows=2261780 width=0) (actual time=2193.075..2193.075 rows=2259270 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6133 written=2 Total runtime: 26727.210 ms (33 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT