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 >= '1994-05-01' and l_shipdate < date'1994-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=2364937.52..2370034.37 rows=3710 width=79) (actual time=17910.890..17910.893 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue1.supplier_no) Buffers: shared hit=430673 read=894257 dirtied=656 written=472 InitPlan 1 (returns $0) -> Aggregate (cost=1173979.15..1173979.16 rows=1 width=8) (actual time=8545.171..8545.171 rows=1 loops=1) Buffers: shared hit=175084 read=486402 written=135 -> HashAggregate (cost=1173895.68..1173932.78 rows=3710 width=12) (actual time=8512.876..8535.991 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=175084 read=486402 written=135 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47292.48..1151550.40 rows=2234528 width=12) (actual time=1106.791..6902.090 rows=2245041 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655348 Buffers: shared hit=175084 read=486402 written=135 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46733.85 rows=2234528 width=0) (actual time=819.495..819.495 rows=2256575 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6138 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.039..25.807 rows=71902 loops=1) Buffers: shared hit=1958 -> Sort (cost=1190958.06..1190967.34 rows=3710 width=12) (actual time=17878.657..17878.658 rows=1 loops=1) Sort Key: revenue1.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=428715 read=894257 dirtied=656 written=472 -> Subquery Scan on revenue1 (cost=1190654.64..1190738.11 rows=3710 width=12) (actual time=17873.413..17878.625 rows=1 loops=1) Buffers: shared hit=428715 read=894257 dirtied=656 written=472 -> HashAggregate (cost=1190654.64..1190701.01 rows=3710 width=12) (actual time=17873.411..17878.622 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=428715 read=894257 dirtied=656 written=472 -> Bitmap Heap Scan on lineitem (cost=47292.48..1151550.40 rows=2234528 width=12) (actual time=1056.014..7656.893 rows=2245041 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655348 Buffers: shared hit=253631 read=407855 dirtied=656 written=337 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46733.85 rows=2234528 width=0) (actual time=789.017..789.017 rows=2256575 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6136 Planning time: 2.107 ms Execution time: 17921.874 ms (38 rows) drop view revenue1; DROP VIEW COMMIT; COMMIT