BEGIN; BEGIN create or replace view revenue17 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-08-01' and l_shipdate < date'1996-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, revenue17 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue17 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2372293.69..2377390.90 rows=3716 width=79) (actual time=58184.283..58184.285 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue17.supplier_no) Buffers: shared hit=609588 read=717789 dirtied=1098 written=17712 InitPlan 1 (returns $0) -> Aggregate (cost=1177614.72..1177614.73 rows=1 width=8) (actual time=28710.710..28710.710 rows=1 loops=1) Buffers: shared hit=267120 read=395722 written=729 -> HashAggregate (cost=1177531.11..1177568.27 rows=3716 width=12) (actual time=28612.431..28694.630 rows=100000 loops=1) Buffers: shared hit=267120 read=395722 written=729 -> Bitmap Heap Scan on lineitem (cost=47466.81..1155072.59 rows=2245852 width=12) (actual time=2342.889..24443.239 rows=2244998 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=267120 read=395722 written=729 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46905.35 rows=2245852 width=0) (actual time=1925.514..1925.514 rows=2265021 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=53 read=6085 written=366 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.090..42.703 rows=61965 loops=1) Buffers: shared hit=1691 read=1 -> Sort (cost=1194678.96..1194688.25 rows=3716 width=12) (actual time=58133.927..58133.928 rows=1 loops=1) Sort Key: revenue17.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=607897 read=717788 dirtied=1098 written=17712 -> Subquery Scan on revenue17 (cost=1194375.00..1194458.61 rows=3716 width=12) (actual time=58092.182..58133.884 rows=1 loops=1) Buffers: shared hit=607897 read=717788 dirtied=1098 written=17712 -> HashAggregate (cost=1194375.00..1194421.45 rows=3716 width=12) (actual time=58092.180..58133.877 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=607897 read=717788 dirtied=1098 written=17712 -> Bitmap Heap Scan on lineitem (cost=47466.81..1155072.59 rows=2245852 width=12) (actual time=2763.931..24865.377 rows=2244998 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=340777 read=322066 dirtied=1098 written=16983 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46905.35 rows=2245852 width=0) (actual time=2100.121..2100.121 rows=2262820 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=11 read=6128 Total runtime: 58196.365 ms (33 rows) drop view revenue17; DROP VIEW COMMIT; COMMIT