BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-10-01' and l_shipdate < date'1995-10-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2382936.42..2388033.69 rows=3738 width=79) (actual time=22535.460..22535.464 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=591277 read=740775 written=15880 InitPlan 1 (returns $0) -> Aggregate (cost=1182848.26..1182848.27 rows=1 width=8) (actual time=9083.818..9083.818 rows=1 loops=1) Buffers: shared hit=355354 read=310178 written=206 -> HashAggregate (cost=1182764.15..1182801.53 rows=3738 width=12) (actual time=9040.924..9073.125 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=355354 read=310178 written=206 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47850.20..1160073.77 rows=2269038 width=12) (actual time=1375.007..7202.802 rows=2243175 loops=1) Recheck Cond: ((l_shipdate >= '1995-10-01'::date) AND (l_shipdate < '1995-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659399 Buffers: shared hit=355354 read=310178 written=206 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47282.95 rows=2269038 width=0) (actual time=1044.927..1044.927 rows=2272494 loops=1) Index Cond: ((l_shipdate >= '1995-10-01'::date) AND (l_shipdate < '1995-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6133 written=14 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.034..14.457 rows=35992 loops=1) Buffers: shared hit=988 -> Sort (cost=1200087.86..1200097.20 rows=3738 width=12) (actual time=22517.503..22517.505 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=590289 read=740775 written=15880 -> Subquery Scan on revenue7 (cost=1199781.94..1199866.04 rows=3738 width=12) (actual time=22517.184..22517.473 rows=1 loops=1) Buffers: shared hit=590289 read=740775 written=15880 -> HashAggregate (cost=1199781.94..1199828.66 rows=3738 width=12) (actual time=22517.182..22517.470 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=590289 read=740775 written=15880 -> Bitmap Heap Scan on lineitem (cost=47850.20..1160073.77 rows=2269038 width=12) (actual time=1807.667..10485.906 rows=2243175 loops=1) Recheck Cond: ((l_shipdate >= '1995-10-01'::date) AND (l_shipdate < '1995-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659399 Buffers: shared hit=234935 read=430597 written=15674 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47282.95 rows=2269038 width=0) (actual time=1486.173..1486.173 rows=2270557 loops=1) Index Cond: ((l_shipdate >= '1995-10-01'::date) AND (l_shipdate < '1995-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=269 read=5864 written=5 Planning time: 3.135 ms Execution time: 22548.761 ms (38 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT