BEGIN; BEGIN create or replace view revenue9 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-06-01' and l_shipdate < date'1995-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, revenue9 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue9 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2371300.25..2376397.72 rows=3734 width=79) (actual time=68749.118..68749.123 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue9.supplier_no) Buffers: shared hit=571260 read=755774 dirtied=570 written=15775 InitPlan 1 (returns $0) -> Aggregate (cost=1177084.97..1177084.98 rows=1 width=8) (actual time=26207.745..26207.745 rows=1 loops=1) Buffers: shared hit=280120 read=382435 written=77 -> HashAggregate (cost=1177000.95..1177038.29 rows=3734 width=12) (actual time=26140.530..26195.948 rows=100000 loops=1) Buffers: shared hit=280120 read=382435 written=77 -> Bitmap Heap Scan on lineitem (cost=47671.45..1154455.95 rows=2254500 width=12) (actual time=3600.371..21609.894 rows=2244011 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=280120 read=382435 written=77 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47107.83 rows=2254500 width=0) (actual time=3212.127..3212.127 rows=2262297 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6134 written=3 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.083..35.795 rows=70652 loops=1) Buffers: shared hit=1923 -> Sort (cost=1194215.27..1194224.60 rows=3734 width=12) (actual time=68705.459..68705.461 rows=1 loops=1) Sort Key: revenue9.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=569337 read=755774 dirtied=570 written=15775 -> Subquery Scan on revenue9 (cost=1193909.70..1193993.72 rows=3734 width=12) (actual time=68663.857..68705.422 rows=1 loops=1) Buffers: shared hit=569337 read=755774 dirtied=570 written=15775 -> HashAggregate (cost=1193909.70..1193956.38 rows=3734 width=12) (actual time=68663.855..68705.417 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=569337 read=755774 dirtied=570 written=15775 -> Bitmap Heap Scan on lineitem (cost=47671.45..1154455.95 rows=2254500 width=12) (actual time=3094.512..37408.367 rows=2244011 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=289217 read=373339 dirtied=570 written=15698 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47107.83 rows=2254500 width=0) (actual time=2348.926..2348.926 rows=2260290 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=322 read=5814 Total runtime: 68766.514 ms (33 rows) drop view revenue9; DROP VIEW COMMIT; COMMIT