BEGIN; BEGIN create or replace view revenue2 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-07-01' and l_shipdate < date'1997-07-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, revenue2 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue2 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2367874.60..2372972.14 rows=3756 width=79) (actual time=18228.017..18228.022 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue2.supplier_no) Buffers: shared hit=771565 read=553312 written=92 InitPlan 1 (returns $0) -> Aggregate (cost=1175335.97..1175335.98 rows=1 width=8) (actual time=8695.572..8695.572 rows=1 loops=1) Buffers: shared hit=364731 read=297214 written=92 -> HashAggregate (cost=1175251.46..1175289.02 rows=3756 width=12) (actual time=8654.542..8685.492 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=364731 read=297214 written=92 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47913.66..1152612.34 rows=2263912 width=12) (actual time=1253.909..6829.001 rows=2246881 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655808 Buffers: shared hit=364731 read=297214 written=92 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47347.68 rows=2263912 width=0) (actual time=954.774..954.774 rows=2255901 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 written=4 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.036..14.109 rows=35977 loops=1) Buffers: shared hit=987 -> Sort (cost=1192538.33..1192547.72 rows=3756 width=12) (actual time=18210.398..18210.401 rows=1 loops=1) Sort Key: revenue2.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=770578 read=553312 written=92 -> Subquery Scan on revenue2 (cost=1192230.80..1192315.31 rows=3756 width=12) (actual time=18196.252..18210.368 rows=1 loops=1) Buffers: shared hit=770578 read=553312 written=92 -> HashAggregate (cost=1192230.80..1192277.75 rows=3756 width=12) (actual time=18196.250..18210.364 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=770578 read=553312 written=92 -> Bitmap Heap Scan on lineitem (cost=47913.66..1152612.34 rows=2263912 width=12) (actual time=1311.974..7621.567 rows=2246881 loops=1) Recheck Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655808 Buffers: shared hit=405847 read=256098 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47347.68 rows=2263912 width=0) (actual time=1007.040..1007.040 rows=2255901 loops=1) Index Cond: ((l_shipdate >= '1997-07-01'::date) AND (l_shipdate < '1997-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 Planning time: 2.619 ms Execution time: 18247.917 ms (38 rows) drop view revenue2; DROP VIEW COMMIT; COMMIT