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 >= '1993-01-01' and l_shipdate < date'1993-01-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=2389987.81..2395085.27 rows=3733 width=79) (actual time=33259.015..33259.019 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=575547 read=762623 dirtied=180 written=1131 InitPlan 1 (returns $0) -> Aggregate (cost=1186344.47..1186344.48 rows=1 width=8) (actual time=15958.059..15958.059 rows=1 loops=1) Buffers: shared hit=221192 read=447156 written=101 -> HashAggregate (cost=1186260.48..1186297.81 rows=3733 width=12) (actual time=15903.410..15947.262 rows=100000 loops=1) Buffers: shared hit=221192 read=447156 written=101 -> Bitmap Heap Scan on lineitem (cost=47953.90..1163490.65 rows=2276983 width=12) (actual time=1860.873..12102.814 rows=2249483 loops=1) Recheck Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=221192 read=447156 written=101 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47384.66 rows=2276983 width=0) (actual time=1446.489..1446.489 rows=2280596 loops=1) Index Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6142 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.061..23.419 rows=53897 loops=1) Buffers: shared hit=1472 read=1 -> Sort (cost=1203643.33..1203652.66 rows=3733 width=12) (actual time=33230.276..33230.278 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=574075 read=762622 dirtied=180 written=1131 -> Subquery Scan on revenue7 (cost=1203337.85..1203421.84 rows=3733 width=12) (actual time=33200.582..33230.240 rows=1 loops=1) Buffers: shared hit=574075 read=762622 dirtied=180 written=1131 -> HashAggregate (cost=1203337.85..1203384.51 rows=3733 width=12) (actual time=33200.580..33230.237 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=574075 read=762622 dirtied=180 written=1131 -> Bitmap Heap Scan on lineitem (cost=47953.90..1163490.65 rows=2276983 width=12) (actual time=2443.974..13420.327 rows=2249483 loops=1) Recheck Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=352883 read=315466 dirtied=180 written=1030 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47384.66 rows=2276983 width=0) (actual time=2055.056..2055.056 rows=2280596 loops=1) Index Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=6 read=6139 Total runtime: 33276.257 ms (33 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT