BEGIN; BEGIN create or replace view revenue19 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-06-01' and l_shipdate < date'1993-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, revenue19 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue19 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2366314.67..2371412.67 rows=3769 width=79) (actual time=98748.199..98748.203 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue19.supplier_no) Buffers: shared hit=675642 read=645441 written=2 InitPlan 1 (returns $0) -> Aggregate (cost=1174536.18..1174536.19 rows=1 width=8) (actual time=46446.696..46446.696 rows=1 loops=1) Buffers: shared hit=365021 read=295255 -> HashAggregate (cost=1174451.38..1174489.07 rows=3769 width=12) (actual time=46357.566..46430.874 rows=100000 loops=1) Buffers: shared hit=365021 read=295255 -> Bitmap Heap Scan on lineitem (cost=48057.33..1151760.16 rows=2269122 width=12) (actual time=2987.874..41531.831 rows=2248010 loops=1) Recheck Cond: ((l_shipdate >= '1993-06-01'::date) AND (l_shipdate < '1993-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=365021 read=295255 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47490.05 rows=2269122 width=0) (actual time=2542.091..2542.091 rows=2254677 loops=1) Index Cond: ((l_shipdate >= '1993-06-01'::date) AND (l_shipdate < '1993-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.099..15.940 rows=18896 loops=1) Buffers: shared hit=529 read=1 -> Sort (cost=1191778.48..1191787.90 rows=3769 width=12) (actual time=98729.049..98729.050 rows=1 loops=1) Sort Key: revenue19.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=675113 read=645440 written=2 -> Subquery Scan on revenue19 (cost=1191469.79..1191554.60 rows=3769 width=12) (actual time=98706.031..98729.019 rows=1 loops=1) Buffers: shared hit=675113 read=645440 written=2 -> HashAggregate (cost=1191469.79..1191516.91 rows=3769 width=12) (actual time=98706.029..98729.015 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=675113 read=645440 written=2 -> Bitmap Heap Scan on lineitem (cost=48057.33..1151760.16 rows=2269122 width=12) (actual time=2940.104..47156.375 rows=2248010 loops=1) Recheck Cond: ((l_shipdate >= '1993-06-01'::date) AND (l_shipdate < '1993-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=310092 read=350185 written=2 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47490.05 rows=2269122 width=0) (actual time=2559.398..2559.398 rows=2254677 loops=1) Index Cond: ((l_shipdate >= '1993-06-01'::date) AND (l_shipdate < '1993-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 Total runtime: 98763.682 ms (33 rows) drop view revenue19; DROP VIEW COMMIT; COMMIT