BEGIN; BEGIN create or replace view revenue16 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-06-01' and l_shipdate < date'1997-06-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, revenue16 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue16 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2377140.16..2382237.78 rows=3761 width=79) (actual time=19094.994..19094.999 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue16.supplier_no) Buffers: shared hit=683173 read=646365 written=1593 InitPlan 1 (returns $0) -> Aggregate (cost=1179931.62..1179931.63 rows=1 width=8) (actual time=9142.687..9142.688 rows=1 loops=1) Buffers: shared hit=342141 read=322039 written=447 -> HashAggregate (cost=1179846.99..1179884.60 rows=3761 width=12) (actual time=9099.433..9132.439 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=342141 read=322039 written=447 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48026.72..1157109.28 rows=2273771 width=12) (actual time=1236.840..7302.212 rows=2245594 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658046 Buffers: shared hit=342141 read=322039 written=447 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47458.28 rows=2273771 width=0) (actual time=936.482..936.482 rows=2263779 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6133 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.036..17.316 rows=42993 loops=1) Buffers: shared hit=1178 -> Sort (cost=1197208.24..1197217.65 rows=3761 width=12) (actual time=19073.407..19073.409 rows=1 loops=1) Sort Key: revenue16.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=681995 read=646365 written=1593 -> Subquery Scan on revenue16 (cost=1196900.28..1196984.90 rows=3761 width=12) (actual time=19067.760..19073.374 rows=1 loops=1) Buffers: shared hit=681995 read=646365 written=1593 -> HashAggregate (cost=1196900.28..1196947.29 rows=3761 width=12) (actual time=19067.759..19073.372 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=681995 read=646365 written=1593 -> Bitmap Heap Scan on lineitem (cost=48026.72..1157109.28 rows=2273771 width=12) (actual time=1301.172..8094.013 rows=2245594 loops=1) Recheck Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658046 Buffers: shared hit=339854 read=324326 written=1146 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47458.28 rows=2273771 width=0) (actual time=996.040..996.040 rows=2263779 loops=1) Index Cond: ((l_shipdate >= '1997-06-01'::date) AND (l_shipdate < '1997-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6131 written=43 Planning time: 2.691 ms Execution time: 19110.939 ms (38 rows) drop view revenue16; DROP VIEW COMMIT; COMMIT