BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-07-01' and l_shipdate < date'1997-07-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2364723.21..2369821.28 rows=3774 width=79) (actual time=37541.662..37541.667 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=668803 read=653548 written=20 InitPlan 1 (returns $0) -> Aggregate (cost=1173722.40..1173722.41 rows=1 width=8) (actual time=18284.031..18284.031 rows=1 loops=1) Buffers: shared hit=348341 read=312340 -> HashAggregate (cost=1173637.49..1173675.23 rows=3774 width=12) (actual time=18186.145..18265.625 rows=100000 loops=1) Buffers: shared hit=348341 read=312340 -> Bitmap Heap Scan on lineitem (cost=48182.21..1150898.58 rows=2273891 width=12) (actual time=1939.090..14048.508 rows=2247022 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=348341 read=312340 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47613.74 rows=2273891 width=0) (actual time=1518.165..1518.165 rows=2251572 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.104..22.905 rows=35977 loops=1) Buffers: shared hit=987 read=1 -> Sort (cost=1191000.80..1191010.23 rows=3774 width=12) (actual time=37512.465..37512.466 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=667816 read=653547 written=20 -> Subquery Scan on revenue5 (cost=1190691.67..1190776.58 rows=3774 width=12) (actual time=37480.242..37512.424 rows=1 loops=1) Buffers: shared hit=667816 read=653547 written=20 -> HashAggregate (cost=1190691.67..1190738.84 rows=3774 width=12) (actual time=37480.240..37512.420 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=667816 read=653547 written=20 -> Bitmap Heap Scan on lineitem (cost=48182.21..1150898.58 rows=2273891 width=12) (actual time=2206.030..15225.687 rows=2247022 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=319475 read=341207 written=20 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47613.74 rows=2273891 width=0) (actual time=1823.590..1823.590 rows=2251572 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 written=1 Total runtime: 37563.282 ms (33 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT