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 >= '1997-07-01' and l_shipdate < date'1997-07-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=2371007.70..2376104.81 rows=3727 width=79) (actual time=20285.782..20285.787 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=545407 read=782056 written=297 InitPlan 1 (returns $0) -> Aggregate (cost=1176941.16..1176941.17 rows=1 width=8) (actual time=9252.104..9252.105 rows=1 loops=1) Buffers: shared hit=304063 read=359175 written=231 -> HashAggregate (cost=1176857.31..1176894.58 rows=3727 width=12) (actual time=9207.659..9241.880 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=304063 read=359175 written=231 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47654.68..1154318.66 rows=2253865 width=12) (actual time=1289.179..7391.050 rows=2246626 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657101 Buffers: shared hit=304063 read=359175 written=231 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47091.22 rows=2253865 width=0) (actual time=973.818..973.818 rows=2260343 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.033..12.945 rows=35977 loops=1) Buffers: shared hit=987 -> Sort (cost=1194066.23..1194075.55 rows=3727 width=12) (actual time=20269.191..20269.193 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=544420 read=782056 written=297 -> Subquery Scan on revenue9 (cost=1193761.29..1193845.15 rows=3727 width=12) (actual time=20253.332..20269.161 rows=1 loops=1) Buffers: shared hit=544420 read=782056 written=297 -> HashAggregate (cost=1193761.29..1193807.88 rows=3727 width=12) (actual time=20253.331..20269.159 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=544420 read=782056 written=297 -> Bitmap Heap Scan on lineitem (cost=47654.68..1154318.66 rows=2253865 width=12) (actual time=1342.039..9001.711 rows=2246626 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657101 Buffers: shared hit=240357 read=422881 written=66 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47091.22 rows=2253865 width=0) (actual time=1014.084..1014.084 rows=2260343 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 Planning time: 2.752 ms Execution time: 20298.728 ms (38 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT