BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-08-01' and l_shipdate < date'1994-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2360477.62..2365575.01 rows=3746 width=79) (actual time=26321.796..26321.801 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=553844 read=765854 written=13614 InitPlan 1 (returns $0) -> Aggregate (cost=1171681.27..1171681.28 rows=1 width=8) (actual time=12767.534..12767.534 rows=1 loops=1) Buffers: shared hit=245279 read=413915 written=13602 -> HashAggregate (cost=1171596.99..1171634.45 rows=3746 width=12) (actual time=12717.734..12757.830 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=245279 read=413915 written=13602 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47742.89..1149073.75 rows=2252324 width=12) (actual time=2290.390..10276.390 rows=2247704 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653054 Buffers: shared hit=245279 read=413915 written=13602 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47179.81 rows=2252324 width=0) (actual time=1766.332..1766.332 rows=2249910 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.029..18.801 rows=47970 loops=1) Buffers: shared hit=1310 -> Sort (cost=1188796.05..1188805.41 rows=3746 width=12) (actual time=26298.616..26298.618 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=552534 read=765854 written=13614 -> Subquery Scan on revenue5 (cost=1188489.42..1188573.70 rows=3746 width=12) (actual time=26296.707..26298.585 rows=1 loops=1) Buffers: shared hit=552534 read=765854 written=13614 -> HashAggregate (cost=1188489.42..1188536.24 rows=3746 width=12) (actual time=26296.706..26298.582 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=552534 read=765854 written=13614 -> Bitmap Heap Scan on lineitem (cost=47742.89..1149073.75 rows=2252324 width=12) (actual time=3214.509..10860.454 rows=2247704 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653054 Buffers: shared hit=307255 read=351939 written=12 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47179.81 rows=2252324 width=0) (actual time=2681.960..2681.960 rows=2249910 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 Planning time: 2.764 ms Execution time: 26338.770 ms (38 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT