BEGIN; BEGIN create or replace view revenue13 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-11-01' and l_shipdate < date'1993-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, revenue13 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue13 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2387122.15..2392218.91 rows=3686 width=79) (actual time=38321.162..38321.166 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue13.supplier_no) Buffers: shared hit=350212 read=984683 written=191 InitPlan 1 (returns $0) -> Aggregate (cost=1185020.73..1185020.74 rows=1 width=8) (actual time=18383.533..18383.533 rows=1 loops=1) Buffers: shared hit=183637 read=483699 -> HashAggregate (cost=1184937.79..1184974.65 rows=3686 width=12) (actual time=18290.138..18366.075 rows=100000 loops=1) Buffers: shared hit=183637 read=483699 -> Bitmap Heap Scan on lineitem (cost=47348.02..1162454.68 rows=2248311 width=12) (actual time=2375.212..14177.951 rows=2244680 loops=1) Recheck Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=183637 read=483699 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46785.94 rows=2248311 width=0) (actual time=1958.531..1958.531 rows=2275376 loops=1) Index Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6129 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.071..5.048 rows=7917 loops=1) Buffers: shared hit=221 read=1 -> Sort (cost=1202101.42..1202110.63 rows=3686 width=12) (actual time=38314.774..38314.774 rows=1 loops=1) Sort Key: revenue13.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=349991 read=984682 written=191 -> Subquery Scan on revenue13 (cost=1201800.12..1201883.06 rows=3686 width=12) (actual time=38308.185..38314.736 rows=1 loops=1) Buffers: shared hit=349991 read=984682 written=191 -> HashAggregate (cost=1201800.12..1201846.20 rows=3686 width=12) (actual time=38308.183..38314.732 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=349991 read=984682 written=191 -> Bitmap Heap Scan on lineitem (cost=47348.02..1162454.68 rows=2248311 width=12) (actual time=2402.099..15781.181 rows=2244680 loops=1) Recheck Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=166354 read=500983 written=191 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46785.94 rows=2248311 width=0) (actual time=2028.279..2028.279 rows=2275376 loops=1) Index Cond: ((l_shipdate >= '1993-11-01'::date) AND (l_shipdate < '1994-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6130 written=5 Total runtime: 38344.238 ms (33 rows) drop view revenue13; DROP VIEW COMMIT; COMMIT