BEGIN; BEGIN create or replace view revenue11 (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, revenue11 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue11 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2357513.24..2362610.56 rows=3741 width=79) (actual time=27627.059..27627.063 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue11.supplier_no) Buffers: shared hit=367847 read=949958 written=20814 InitPlan 1 (returns $0) -> Aggregate (cost=1170231.84..1170231.85 rows=1 width=8) (actual time=11335.509..11335.509 rows=1 loops=1) Buffers: shared hit=251711 read=406631 written=6607 -> HashAggregate (cost=1170147.66..1170185.07 rows=3741 width=12) (actual time=11282.817..11325.246 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=251711 read=406631 written=6607 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47581.81..1147711.32 rows=2243634 width=12) (actual time=1774.312..8847.420 rows=2243279 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652208 Buffers: shared hit=251711 read=406631 written=6607 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47020.90 rows=2243634 width=0) (actual time=1385.808..1385.808 rows=2247728 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=554 read=5580 written=265 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.034..16.252 rows=40970 loops=1) Buffers: shared hit=1121 -> Sort (cost=1187281.10..1187290.46 rows=3741 width=12) (actual time=27606.862..27606.864 rows=1 loops=1) Sort Key: revenue11.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=366726 read=949958 written=20814 -> Subquery Scan on revenue11 (cost=1186974.92..1187059.09 rows=3741 width=12) (actual time=27592.513..27606.820 rows=1 loops=1) Buffers: shared hit=366726 read=949958 written=20814 -> HashAggregate (cost=1186974.92..1187021.68 rows=3741 width=12) (actual time=27592.512..27606.817 rows=1 loops=1) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=366726 read=949958 written=20814 -> Bitmap Heap Scan on lineitem (cost=47581.81..1147711.32 rows=2243634 width=12) (actual time=3064.030..13101.655 rows=2243279 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652208 Buffers: shared hit=115015 read=543327 written=14207 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47020.90 rows=2243634 width=0) (actual time=2599.206..2599.206 rows=2245705 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=6132 Planning time: 2.665 ms Execution time: 27649.093 ms (38 rows) drop view revenue11; DROP VIEW COMMIT; COMMIT