BEGIN; BEGIN create or replace view revenue7 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-11-01' and l_shipdate < date'1994-11-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, revenue7 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue7 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2384465.78..2389562.83 rows=3723 width=79) (actual time=20230.203..20230.208 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue7.supplier_no) Buffers: shared hit=849016 read=485466 dirtied=515 written=841 InitPlan 1 (returns $0) -> Aggregate (cost=1183635.02..1183635.03 rows=1 width=8) (actual time=9405.439..9405.439 rows=1 loops=1) Buffers: shared hit=409251 read=257470 written=411 -> HashAggregate (cost=1183551.26..1183588.49 rows=3723 width=12) (actual time=9360.778..9394.898 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=409251 read=257470 written=411 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47707.21..1160918.44 rows=2263282 width=12) (actual time=1401.064..7438.960 rows=2246551 loops=1) Recheck Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660584 Buffers: shared hit=409251 read=257470 written=411 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47141.39 rows=2263282 width=0) (actual time=1065.225..1065.225 rows=2273926 loops=1) Index Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6135 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.031..16.148 rows=37989 loops=1) Buffers: shared hit=1040 -> Sort (cost=1200830.45..1200839.76 rows=3723 width=12) (actual time=20210.123..20210.126 rows=1 loops=1) Sort Key: revenue7.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=847976 read=485466 dirtied=515 written=841 -> Subquery Scan on revenue7 (cost=1200525.87..1200609.64 rows=3723 width=12) (actual time=20195.249..20210.099 rows=1 loops=1) Buffers: shared hit=847976 read=485466 dirtied=515 written=841 -> HashAggregate (cost=1200525.87..1200572.41 rows=3723 width=12) (actual time=20195.248..20210.097 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=847976 read=485466 dirtied=515 written=841 -> Bitmap Heap Scan on lineitem (cost=47707.21..1160918.44 rows=2263282 width=12) (actual time=1904.366..8583.232 rows=2246551 loops=1) Recheck Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660584 Buffers: shared hit=438725 read=227996 dirtied=515 written=430 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47141.39 rows=2263282 width=0) (actual time=1477.191..1477.191 rows=2273926 loops=1) Index Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6134 written=21 Planning time: 2.588 ms Execution time: 20239.062 ms (38 rows) drop view revenue7; DROP VIEW COMMIT; COMMIT