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 >= '1996-08-01' and l_shipdate < date'1996-08-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=2394823.37..2399921.79 rows=3797 width=79) (actual time=101924.507..101924.511 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=680088 read=657316 written=6897 InitPlan 1 (returns $0) -> Aggregate (cost=1188627.41..1188627.42 rows=1 width=8) (actual time=43783.358..43783.359 rows=1 loops=1) Buffers: shared hit=389539 read=278316 written=49 -> HashAggregate (cost=1188541.98..1188579.95 rows=3797 width=12) (actual time=43699.114..43769.937 rows=100000 loops=1) Buffers: shared hit=389539 read=278316 written=49 -> Bitmap Heap Scan on lineitem (cost=48684.65..1165418.25 rows=2312373 width=12) (actual time=3064.268..38778.972 rows=2245045 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=389539 read=278316 written=49 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48106.56 rows=2312373 width=0) (actual time=2648.812..2648.812 rows=2281025 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.685..61.142 rows=61965 loops=1) Buffers: shared hit=1691 read=1 -> Sort (cost=1206195.95..1206205.44 rows=3797 width=12) (actual time=101852.683..101852.683 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=678397 read=657315 written=6897 -> Subquery Scan on revenue7 (cost=1205884.77..1205970.21 rows=3797 width=12) (actual time=101781.976..101852.618 rows=1 loops=1) Buffers: shared hit=678397 read=657315 written=6897 -> HashAggregate (cost=1205884.77..1205932.24 rows=3797 width=12) (actual time=101781.973..101852.614 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=678397 read=657315 written=6897 -> Bitmap Heap Scan on lineitem (cost=48684.65..1165418.25 rows=2312373 width=12) (actual time=3119.965..53084.554 rows=2245045 loops=1) Recheck Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=288858 read=378999 written=6848 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48106.56 rows=2312373 width=0) (actual time=2661.385..2661.385 rows=2280246 loops=1) Index Cond: ((l_shipdate >= '1996-08-01'::date) AND (l_shipdate < '1996-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=551 read=5588 written=211 Total runtime: 101943.376 ms (33 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT