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 >= '1996-09-01' and l_shipdate < date'1996-09-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=2379417.33..2384515.03 rows=3749 width=79) (actual time=34895.374..34895.383 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue16.supplier_no) Buffers: shared hit=399473 read=931073 written=232 InitPlan 1 (returns $0) -> Aggregate (cost=1181063.91..1181063.92 rows=1 width=8) (actual time=16469.423..16469.423 rows=1 loops=1) Buffers: shared hit=248467 read=415878 written=222 -> HashAggregate (cost=1180979.55..1181017.04 rows=3749 width=12) (actual time=16379.306..16451.529 rows=100000 loops=1) Buffers: shared hit=248467 read=415878 written=222 -> Bitmap Heap Scan on lineitem (cost=48043.68..1158223.60 rows=2275595 width=12) (actual time=2456.974..12447.461 rows=2249057 loops=1) Recheck Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=248467 read=415878 written=222 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47474.78 rows=2275595 width=0) (actual time=1990.309..1990.309 rows=2269346 loops=1) Index Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6142 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.049..43.788 rows=67992 loops=1) Buffers: shared hit=1855 -> Sort (cost=1198353.41..1198362.79 rows=3749 width=12) (actual time=34839.717..34839.719 rows=1 loops=1) Sort Key: revenue16.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=397618 read=931073 written=232 -> Subquery Scan on revenue16 (cost=1198046.52..1198130.87 rows=3749 width=12) (actual time=34792.700..34839.680 rows=1 loops=1) Buffers: shared hit=397618 read=931073 written=232 -> HashAggregate (cost=1198046.52..1198093.38 rows=3749 width=12) (actual time=34792.698..34839.676 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=397618 read=931073 written=232 -> Bitmap Heap Scan on lineitem (cost=48043.68..1158223.60 rows=2275595 width=12) (actual time=1242.095..14263.430 rows=2249057 loops=1) Recheck Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=149151 read=515195 written=10 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47474.78 rows=2275595 width=0) (actual time=845.793..845.793 rows=2269346 loops=1) Index Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6140 read=4 Total runtime: 34913.568 ms (33 rows) drop view revenue16; DROP VIEW COMMIT; COMMIT