BEGIN; BEGIN create or replace view revenue22 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-04-01' and l_shipdate < date'1996-04-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, revenue22 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue22 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2378782.14..2383878.65 rows=3670 width=79) (actual time=93374.544..93374.549 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue22.supplier_no) Buffers: shared hit=536106 read=795889 written=72 InitPlan 1 (returns $0) -> Aggregate (cost=1180930.01..1180930.02 rows=1 width=8) (actual time=43821.948..43821.948 rows=1 loops=1) Buffers: shared hit=288931 read=376505 -> HashAggregate (cost=1180847.44..1180884.14 rows=3670 width=12) (actual time=43756.088..43810.406 rows=100000 loops=1) Buffers: shared hit=288931 read=376505 -> Bitmap Heap Scan on lineitem (cost=46976.74..1158574.36 rows=2227308 width=12) (actual time=2912.021..39025.414 rows=2246905 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=288931 read=376505 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46419.91 rows=2227308 width=0) (actual time=2439.937..2439.937 rows=2271021 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.119..29.529 rows=40980 loops=1) Buffers: shared hit=1121 read=1 -> Sort (cost=1197852.11..1197861.29 rows=3670 width=12) (actual time=93339.094..93339.096 rows=1 loops=1) Sort Key: revenue22.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=534985 read=795888 written=72 -> Subquery Scan on revenue22 (cost=1197552.25..1197634.82 rows=3670 width=12) (actual time=93329.170..93339.054 rows=1 loops=1) Buffers: shared hit=534985 read=795888 written=72 -> HashAggregate (cost=1197552.25..1197598.12 rows=3670 width=12) (actual time=93329.168..93339.049 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=534985 read=795888 written=72 -> Bitmap Heap Scan on lineitem (cost=46976.74..1158574.36 rows=2227308 width=12) (actual time=2730.093..44382.282 rows=2246905 loops=1) Recheck Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=246054 read=419383 written=72 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46419.91 rows=2227308 width=0) (actual time=2347.197..2347.197 rows=2271021 loops=1) Index Cond: ((l_shipdate >= '1996-04-01'::date) AND (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6136 Total runtime: 93388.364 ms (33 rows) drop view revenue22; DROP VIEW COMMIT; COMMIT