BEGIN; BEGIN create or replace view revenue6 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-04-01' and l_shipdate < date'1993-04-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, revenue6 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue6 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2359454.93..2364551.77 rows=3709 width=79) (actual time=21600.438..21600.443 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue6.supplier_no) Buffers: shared hit=855291 read=465736 dirtied=26 written=3888 InitPlan 1 (returns $0) -> Aggregate (cost=1171254.55..1171254.56 rows=1 width=8) (actual time=9806.548..9806.548 rows=1 loops=1) Buffers: shared hit=445202 read=215061 written=73 -> HashAggregate (cost=1171171.10..1171208.19 rows=3709 width=12) (actual time=9722.485..9796.065 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=445202 read=215061 written=73 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47258.95..1148870.24 rows=2230086 width=12) (actual time=1276.525..6905.371 rows=2247834 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654118 Buffers: shared hit=445202 read=215061 written=73 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46701.43 rows=2230086 width=0) (actual time=958.750..958.750 rows=2254468 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6144 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.036..7.283 rows=17858 loops=1) Buffers: shared hit=501 -> Sort (cost=1188200.08..1188209.35 rows=3709 width=12) (actual time=21591.393..21591.395 rows=1 loops=1) Sort Key: revenue6.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=854790 read=465736 dirtied=26 written=3888 -> Subquery Scan on revenue6 (cost=1187896.74..1187980.19 rows=3709 width=12) (actual time=21577.076..21591.357 rows=1 loops=1) Buffers: shared hit=854790 read=465736 dirtied=26 written=3888 -> HashAggregate (cost=1187896.74..1187943.10 rows=3709 width=12) (actual time=21577.073..21591.351 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=854790 read=465736 dirtied=26 written=3888 -> Bitmap Heap Scan on lineitem (cost=47258.95..1148870.24 rows=2230086 width=12) (actual time=1744.730..8704.830 rows=2247834 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=654118 Buffers: shared hit=409588 read=250675 dirtied=26 written=3815 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46701.43 rows=2230086 width=0) (actual time=1368.841..1368.841 rows=2253740 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=367 read=5778 written=265 Planning time: 3.383 ms Execution time: 21620.778 ms (38 rows) drop view revenue6; DROP VIEW COMMIT; COMMIT