BEGIN; BEGIN create or replace view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-02-01' and l_shipdate < date'1993-02-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2357513.68..2362610.87 rows=3733 width=79) (actual time=17235.252..17235.259 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=327321 read=991841 InitPlan 1 (returns $0) -> Aggregate (cost=1170232.26..1170232.27 rows=1 width=8) (actual time=6569.030..6569.030 rows=1 loops=1) Buffers: shared hit=316621 read=342224 -> HashAggregate (cost=1170148.26..1170185.59 rows=3733 width=12) (actual time=6539.201..6559.938 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=316621 read=342224 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47581.99..1147711.75 rows=2243651 width=12) (actual time=1317.841..5089.334 rows=2250260 loops=1) Recheck Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652699 Buffers: shared hit=316621 read=342224 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47021.08 rows=2243651 width=0) (actual time=982.613..982.613 rows=2250260 loops=1) Index Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.053..22.005 rows=53897 loops=1) Buffers: shared hit=574 read=898 -> Sort (cost=1187281.12..1187290.45 rows=3733 width=12) (actual time=17208.229..17208.232 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=326747 read=990943 -> Subquery Scan on revenue0 (cost=1186975.65..1187059.64 rows=3733 width=12) (actual time=17187.557..17208.182 rows=1 loops=1) Buffers: shared hit=326747 read=990943 -> HashAggregate (cost=1186975.65..1187022.31 rows=3733 width=12) (actual time=17187.554..17208.177 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=326747 read=990943 -> Bitmap Heap Scan on lineitem (cost=47581.99..1147711.75 rows=2243651 width=12) (actual time=1360.619..8587.860 rows=2250260 loops=1) Recheck Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652699 Buffers: shared hit=10126 read=648719 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47021.08 rows=2243651 width=0) (actual time=1026.612..1026.612 rows=2250260 loops=1) Index Cond: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6146 Planning time: 4.436 ms Execution time: 17242.403 ms (38 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT