BEGIN; BEGIN create or replace view revenue6 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-04-01' and l_shipdate < date'1995-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, revenue6 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue6 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2366157.98..2371256.38 rows=3796 width=79) (actual time=34074.638..34074.648 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue6.supplier_no) Buffers: shared hit=731207 read=590804 dirtied=277 written=707 InitPlan 1 (returns $0) -> Aggregate (cost=1174385.19..1174385.20 rows=1 width=8) (actual time=16027.889..16027.889 rows=1 loops=1) Buffers: shared hit=294928 read=364949 written=78 -> HashAggregate (cost=1174299.78..1174337.74 rows=3796 width=12) (actual time=15930.649..16009.609 rows=100000 loops=1) Buffers: shared hit=294928 read=364949 written=78 -> Bitmap Heap Scan on lineitem (cost=48485.43..1151417.24 rows=2288254 width=12) (actual time=2151.822..12026.698 rows=2248183 loops=1) Recheck Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=294928 read=364949 written=78 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47913.37 rows=2288254 width=0) (actual time=1727.356..1727.356 rows=2252675 loops=1) Index Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6140 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.063..53.908 rows=82932 loops=1) Buffers: shared hit=2256 -> Sort (cost=1191772.77..1191782.26 rows=3796 width=12) (actual time=34006.870..34006.871 rows=1 loops=1) Sort Key: revenue6.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=728951 read=590804 dirtied=277 written=707 -> Subquery Scan on revenue6 (cost=1191461.69..1191547.10 rows=3796 width=12) (actual time=33997.230..34006.837 rows=1 loops=1) Buffers: shared hit=728951 read=590804 dirtied=277 written=707 -> HashAggregate (cost=1191461.69..1191509.14 rows=3796 width=12) (actual time=33997.227..34006.830 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=728951 read=590804 dirtied=277 written=707 -> Bitmap Heap Scan on lineitem (cost=48485.43..1151417.24 rows=2288254 width=12) (actual time=2828.394..13582.867 rows=2248183 loops=1) Recheck Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=434023 read=225855 dirtied=277 written=629 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47913.37 rows=2288254 width=0) (actual time=2424.319..2424.319 rows=2252675 loops=1) Index Cond: ((l_shipdate >= '1995-04-01'::date) AND (l_shipdate < '1995-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=15 read=6127 written=25 Total runtime: 34098.909 ms (33 rows) drop view revenue6; DROP VIEW COMMIT; COMMIT