BEGIN; BEGIN create or replace view revenue4 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-08-01' and l_shipdate < date'1993-08-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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2365639.36..2370737.15 rows=3755 width=79) (actual time=32440.069..32440.075 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=450899 read=872894 InitPlan 1 (returns $0) -> Aggregate (cost=1174224.08..1174224.09 rows=1 width=8) (actual time=14668.191..14668.191 rows=1 loops=1) Buffers: shared hit=253915 read=406622 -> HashAggregate (cost=1174139.59..1174177.14 rows=3755 width=12) (actual time=14592.628..14656.434 rows=100000 loops=1) Buffers: shared hit=253915 read=406622 -> Bitmap Heap Scan on lineitem (cost=47912.77..1151515.26 rows=2262433 width=12) (actual time=2128.760..10912.802 rows=2248668 loops=1) Recheck Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=253915 read=406622 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47347.16 rows=2262433 width=0) (actual time=1707.690..1707.690 rows=2255273 loops=1) Index Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.041..47.872 rows=99925 loops=1) Buffers: shared hit=2718 -> Sort (cost=1191415.27..1191424.66 rows=3755 width=12) (actual time=32381.676..32381.679 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=448181 read=872894 -> Subquery Scan on revenue4 (cost=1191107.84..1191192.33 rows=3755 width=12) (actual time=32371.622..32381.638 rows=1 loops=1) Buffers: shared hit=448181 read=872894 -> HashAggregate (cost=1191107.84..1191154.78 rows=3755 width=12) (actual time=32371.619..32381.632 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=448181 read=872894 -> Bitmap Heap Scan on lineitem (cost=47912.77..1151515.26 rows=2262433 width=12) (actual time=2295.967..13579.171 rows=2248668 loops=1) Recheck Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=194266 read=466272 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47347.16 rows=2262433 width=0) (actual time=1869.402..1869.402 rows=2255273 loops=1) Index Cond: ((l_shipdate >= '1993-08-01'::date) AND (l_shipdate < '1993-10-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6139 Total runtime: 32460.721 ms (33 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT