BEGIN; BEGIN create or replace view revenue17 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-06-01' and l_shipdate < date'1994-06-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, revenue17 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue17 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2374385.83..2379483.45 rows=3744 width=79) (actual time=37564.477..37564.480 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue17.supplier_no) Buffers: shared hit=542914 read=785733 written=363 InitPlan 1 (returns $0) -> Aggregate (cost=1178581.35..1178581.36 rows=1 width=8) (actual time=14842.456..14842.456 rows=1 loops=1) Buffers: shared hit=406268 read=257075 -> HashAggregate (cost=1178497.11..1178534.55 rows=3744 width=12) (actual time=14705.160..14825.696 rows=100000 loops=1) Buffers: shared hit=406268 read=257075 -> Bitmap Heap Scan on lineitem (cost=47909.41..1155829.23 rows=2266788 width=12) (actual time=2195.372..10774.024 rows=2248001 loops=1) Recheck Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=406268 read=257075 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47342.71 rows=2266788 width=0) (actual time=1738.066..1738.066 rows=2263735 loops=1) Index Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.076..51.166 rows=71981 loops=1) Buffers: shared hit=1960 -> Sort (cost=1195804.47..1195813.83 rows=3744 width=12) (actual time=37501.602..37501.602 rows=1 loops=1) Sort Key: revenue17.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=540954 read=785733 written=363 -> Subquery Scan on revenue17 (cost=1195498.02..1195582.26 rows=3744 width=12) (actual time=37433.766..37501.551 rows=1 loops=1) Buffers: shared hit=540954 read=785733 written=363 -> HashAggregate (cost=1195498.02..1195544.82 rows=3744 width=12) (actual time=37433.764..37501.547 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=540954 read=785733 written=363 -> Bitmap Heap Scan on lineitem (cost=47909.41..1155829.23 rows=2266788 width=12) (actual time=2618.743..18207.363 rows=2248001 loops=1) Recheck Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=134686 read=528658 written=363 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47342.71 rows=2266788 width=0) (actual time=1994.015..1994.015 rows=2263735 loops=1) Index Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6138 Total runtime: 37586.419 ms (33 rows) drop view revenue17; DROP VIEW COMMIT; COMMIT