BEGIN; BEGIN create or replace view revenue1 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-05-01' and l_shipdate < date'1996-05-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, revenue1 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue1 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2371896.35..2376993.68 rows=3742 width=79) (actual time=18091.008..18091.012 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue1.supplier_no) Buffers: shared hit=618761 read=707495 written=264 InitPlan 1 (returns $0) -> Aggregate (cost=1177351.58..1177351.59 rows=1 width=8) (actual time=8110.670..8110.670 rows=1 loops=1) Buffers: shared hit=365683 read=296467 written=241 -> HashAggregate (cost=1177267.38..1177304.80 rows=3742 width=12) (actual time=8063.938..8100.417 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=365683 read=296467 written=241 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47842.01..1154639.63 rows=2262775 width=12) (actual time=1148.990..6241.125 rows=2246438 loops=1) Recheck Cond: ((l_shipdate >= '1996-05-01'::date) AND (l_shipdate < '1996-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656016 Buffers: shared hit=365683 read=296467 written=241 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47276.32 rows=2262775 width=0) (actual time=890.631..890.631 rows=2259408 loops=1) Index Cond: ((l_shipdate >= '1996-05-01'::date) AND (l_shipdate < '1996-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.037..27.627 rows=71847 loops=1) Buffers: shared hit=1956 -> Sort (cost=1194544.47..1194553.83 rows=3742 width=12) (actual time=18056.222..18056.224 rows=1 loops=1) Sort Key: revenue1.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=616805 read=707495 written=264 -> Subquery Scan on revenue1 (cost=1194238.20..1194322.39 rows=3742 width=12) (actual time=18048.808..18056.190 rows=1 loops=1) Buffers: shared hit=616805 read=707495 written=264 -> HashAggregate (cost=1194238.20..1194284.97 rows=3742 width=12) (actual time=18048.808..18056.188 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=616805 read=707495 written=264 -> Bitmap Heap Scan on lineitem (cost=47842.01..1154639.63 rows=2262775 width=12) (actual time=1239.683..7931.176 rows=2246438 loops=1) Recheck Cond: ((l_shipdate >= '1996-05-01'::date) AND (l_shipdate < '1996-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656016 Buffers: shared hit=251122 read=411028 written=23 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47276.32 rows=2262775 width=0) (actual time=958.069..958.069 rows=2259408 loops=1) Index Cond: ((l_shipdate >= '1996-05-01'::date) AND (l_shipdate < '1996-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 written=5 Planning time: 2.612 ms Execution time: 18098.825 ms (38 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT