BEGIN; BEGIN create or replace view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-07-01' and l_shipdate < date'1996-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2359202.71..2364300.71 rows=3769 width=79) (actual time=13211.375..13211.381 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=731964 read=585841 InitPlan 1 (returns $0) -> Aggregate (cost=1171012.99..1171013.00 rows=1 width=8) (actual time=3764.459..3764.460 rows=1 loops=1) Buffers: shared hit=657007 read=1063 -> HashAggregate (cost=1170928.19..1170965.88 rows=3769 width=12) (actual time=3734.363..3754.913 rows=100000 loops=1) Buffers: shared hit=657007 read=1063 -> Bitmap Heap Scan on lineitem (cost=47943.71..1148324.40 rows=2260379 width=12) (actual time=808.224..2524.301 rows=2245864 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=657007 read=1063 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47378.62 rows=2260379 width=0) (actual time=586.563..586.563 rows=2245864 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=6134 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.058..26.358 rows=60982 loops=1) Buffers: shared hit=1293 read=371 -> Sort (cost=1188189.71..1188199.13 rows=3769 width=12) (actual time=13179.359..13179.361 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=730671 read=585470 -> Subquery Scan on revenue0 (cost=1187881.03..1187965.83 rows=3769 width=12) (actual time=13163.117..13179.303 rows=1 loops=1) Buffers: shared hit=730671 read=585470 -> HashAggregate (cost=1187881.03..1187928.14 rows=3769 width=12) (actual time=13163.117..13179.302 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=730671 read=585470 -> Bitmap Heap Scan on lineitem (cost=47943.71..1148324.40 rows=2260379 width=12) (actual time=913.769..7733.153 rows=2245864 loops=1) Recheck Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared hit=73664 read=584407 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47378.62 rows=2260379 width=0) (actual time=696.767..696.767 rows=2245864 loops=1) Index Cond: ((l_shipdate >= '1996-07-01'::date) AND (l_shipdate < '1996-09-29 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 Total runtime: 13218.492 ms (33 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT