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 >= '1995-09-01' and l_shipdate < date'1995-09-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=2369992.90..2375090.72 rows=3757 width=79) (actual time=28476.855..28476.858 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue2.supplier_no) Buffers: shared hit=367344 read=959643 written=9706 InitPlan 1 (returns $0) -> Aggregate (cost=1176393.80..1176393.81 rows=1 width=8) (actual time=13337.404..13337.404 rows=1 loops=1) Buffers: shared hit=138391 read=523772 written=890 -> HashAggregate (cost=1176309.26..1176346.83 rows=3757 width=12) (actual time=13272.111..13326.489 rows=100000 loops=1) Buffers: shared hit=138391 read=523772 written=890 -> Bitmap Heap Scan on lineitem (cost=47903.86..1153666.30 rows=2264296 width=12) (actual time=1805.608..9930.846 rows=2247629 loops=1) Recheck Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=138391 read=523772 written=890 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47337.79 rows=2264296 width=0) (actual time=1408.925..1408.925 rows=2258843 loops=1) Index Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6136 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.089..36.672 rows=97885 loops=1) Buffers: shared hit=2659 read=1 -> Sort (cost=1193599.09..1193608.49 rows=3757 width=12) (actual time=28429.787..28429.787 rows=1 loops=1) Sort Key: revenue2.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=364685 read=959642 written=9706 -> Subquery Scan on revenue2 (cost=1193291.48..1193376.02 rows=3757 width=12) (actual time=28402.726..28429.750 rows=1 loops=1) Buffers: shared hit=364685 read=959642 written=9706 -> HashAggregate (cost=1193291.48..1193338.45 rows=3757 width=12) (actual time=28402.723..28429.745 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=364685 read=959642 written=9706 -> Bitmap Heap Scan on lineitem (cost=47903.86..1153666.30 rows=2264296 width=12) (actual time=2097.208..11342.751 rows=2247629 loops=1) Recheck Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=226294 read=435870 written=8816 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47337.79 rows=2264296 width=0) (actual time=1671.058..1671.058 rows=2258843 loops=1) Index Cond: ((l_shipdate >= '1995-09-01'::date) AND (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=492 read=5648 written=1006 Total runtime: 28491.433 ms (33 rows) drop view revenue2; DROP VIEW COMMIT; COMMIT