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=2388560.17..2393657.32 rows=3712 width=79) (actual time=46234.893..46234.896 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue13.supplier_no) Buffers: shared hit=477977 read=856918 written=5 InitPlan 1 (returns $0) -> Aggregate (cost=1185684.88..1185684.89 rows=1 width=8) (actual time=22709.358..22709.358 rows=1 loops=1) Buffers: shared hit=268454 read=398882 written=1 -> HashAggregate (cost=1185601.36..1185638.48 rows=3712 width=12) (actual time=22605.965..22691.785 rows=100000 loops=1) Buffers: shared hit=268454 read=398882 written=1 -> Bitmap Heap Scan on lineitem (cost=47651.61..1162974.26 rows=2262710 width=12) (actual time=2856.637..18138.942 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=268454 read=398882 written=1 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47085.93 rows=2262710 width=0) (actual time=2374.329..2374.329 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 hit=1 read=6128 written=1 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.075..4.051 rows=7917 loops=1) Buffers: shared hit=221 read=1 -> Sort (cost=1202875.29..1202884.57 rows=3712 width=12) (actual time=46229.998..46229.999 rows=1 loops=1) Sort Key: revenue13.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=477756 read=856917 written=5 -> Subquery Scan on revenue13 (cost=1202571.68..1202655.20 rows=3712 width=12) (actual time=46224.711..46229.948 rows=1 loops=1) Buffers: shared hit=477756 read=856917 written=5 -> HashAggregate (cost=1202571.68..1202618.08 rows=3712 width=12) (actual time=46224.709..46229.941 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=477756 read=856917 written=5 -> Bitmap Heap Scan on lineitem (cost=47651.61..1162974.26 rows=2262710 width=12) (actual time=2480.945..19041.854 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=209302 read=458035 written=4 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47085.93 rows=2262710 width=0) (actual time=2054.666..2054.666 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 Total runtime: 46250.996 ms (33 rows) drop view revenue13; DROP VIEW COMMIT; COMMIT