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-12-01' and l_shipdate < date'1995-12-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=2355751.59..2360847.89 rows=3673 width=79) (actual time=21104.654..21104.660 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue6.supplier_no) Buffers: shared hit=721078 read=596625 dirtied=417 written=14045 InitPlan 1 (returns $0) -> Aggregate (cost=1169497.89..1169497.90 rows=1 width=8) (actual time=10643.870..10643.870 rows=1 loops=1) Buffers: shared hit=355350 read=303252 dirtied=1 written=4927 -> HashAggregate (cost=1169415.25..1169451.98 rows=3673 width=12) (actual time=10582.055..10633.795 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=355350 read=303252 dirtied=1 written=4927 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=46742.52..1147364.56 rows=2205069 width=12) (actual time=1191.815..7936.744 rows=2240148 loops=1) Recheck Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652477 Buffers: shared hit=355350 read=303252 dirtied=1 written=4927 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46191.26 rows=2205069 width=0) (actual time=902.003..902.003 rows=2247002 loops=1) Index Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=555 read=5570 written=301 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.038..7.410 rows=17822 loops=1) Buffers: shared hit=500 -> Sort (cost=1186253.40..1186262.58 rows=3673 width=12) (actual time=21095.600..21095.603 rows=1 loops=1) Sort Key: revenue6.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=720578 read=596625 dirtied=417 written=14045 -> Subquery Scan on revenue6 (cost=1185953.26..1186035.91 rows=3673 width=12) (actual time=21070.202..21095.562 rows=1 loops=1) Buffers: shared hit=720578 read=596625 dirtied=417 written=14045 -> HashAggregate (cost=1185953.26..1185999.18 rows=3673 width=12) (actual time=21070.200..21095.558 rows=1 loops=1) Group Key: lineitem.l_suppkey Filter: (sum((lineitem.l_extendedprice * (1::double precision - lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=720578 read=596625 dirtied=417 written=14045 -> Bitmap Heap Scan on lineitem (cost=46742.52..1147364.56 rows=2205069 width=12) (actual time=1289.464..7604.269 rows=2240148 loops=1) Recheck Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652476 Buffers: shared hit=365228 read=293373 dirtied=416 written=9118 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46191.26 rows=2205069 width=0) (actual time=989.156..989.156 rows=2244590 loops=1) Index Cond: ((l_shipdate >= '1995-12-01'::date) AND (l_shipdate < '1996-02-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6125 written=6 Planning time: 2.581 ms Execution time: 21129.977 ms (38 rows) drop view revenue6; DROP VIEW COMMIT; COMMIT