BEGIN; BEGIN create or replace view revenue15 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-08-01' and l_shipdate < date'1997-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, revenue15 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue15 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2379281.73..2384379.48 rows=3752 width=79) (actual time=33223.508..33223.510 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue15.supplier_no) Buffers: shared hit=516435 read=813091 dirtied=652 written=674 InitPlan 1 (returns $0) -> Aggregate (cost=1181001.39..1181001.40 rows=1 width=8) (actual time=13843.552..13843.552 rows=1 loops=1) Buffers: shared hit=428733 read=236014 written=81 -> HashAggregate (cost=1180916.97..1180954.49 rows=3752 width=12) (actual time=13772.064..13833.150 rows=100000 loops=1) Buffers: shared hit=428733 read=236014 written=81 -> Bitmap Heap Scan on lineitem (cost=48016.97..1158175.37 rows=2274160 width=12) (actual time=1945.590..9974.391 rows=2244969 loops=1) Recheck Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=428733 read=236014 written=81 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47448.43 rows=2274160 width=0) (actual time=1581.729..1581.729 rows=2265310 loops=1) Index Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6132 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.095..0.424 rows=973 loops=1) Buffers: shared hit=30 read=1 -> Sort (cost=1198280.34..1198289.72 rows=3752 width=12) (actual time=33222.952..33222.952 rows=1 loops=1) Sort Key: revenue15.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=516405 read=813090 dirtied=652 written=674 -> Subquery Scan on revenue15 (cost=1197973.17..1198057.59 rows=3752 width=12) (actual time=33202.591..33222.920 rows=1 loops=1) Buffers: shared hit=516405 read=813090 dirtied=652 written=674 -> HashAggregate (cost=1197973.17..1198020.07 rows=3752 width=12) (actual time=33202.588..33222.914 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=516405 read=813090 dirtied=652 written=674 -> Bitmap Heap Scan on lineitem (cost=48016.97..1158175.37 rows=2274160 width=12) (actual time=2223.942..15376.430 rows=2244969 loops=1) Recheck Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=87672 read=577076 dirtied=652 written=593 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47448.43 rows=2274160 width=0) (actual time=1824.233..1824.233 rows=2265310 loops=1) Index Cond: ((l_shipdate >= '1997-08-01'::date) AND (l_shipdate < '1997-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6 read=6128 Total runtime: 33238.364 ms (33 rows) drop view revenue15; DROP VIEW COMMIT; COMMIT