BEGIN; BEGIN create or replace view revenue21 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-10-01' and l_shipdate < date'1993-10-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, revenue21 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue21 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363971.24..2369068.66 rows=3730 width=79) (actual time=79119.836..79119.839 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue21.supplier_no) Buffers: shared hit=812527 read=508351 written=16881 InitPlan 1 (returns $0) -> Aggregate (cost=1173453.61..1173453.62 rows=1 width=8) (actual time=38881.526..38881.527 rows=1 loops=1) Buffers: shared hit=411752 read=248393 written=14461 -> HashAggregate (cost=1173369.68..1173406.98 rows=3730 width=12) (actual time=38790.198..38866.230 rows=100000 loops=1) Buffers: shared hit=411752 read=248393 written=14461 -> Bitmap Heap Scan on lineitem (cost=47561.23..1150912.70 rows=2245698 width=12) (actual time=2648.038..34120.834 rows=2246167 loops=1) Recheck Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=411752 read=248393 written=14461 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46999.81 rows=2245698 width=0) (actual time=2157.052..2157.052 rows=2253608 loops=1) Index Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=634 read=5500 written=225 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.059..28.190 rows=20959 loops=1) Buffers: shared hit=587 -> Sort (cost=1190517.63..1190526.95 rows=3730 width=12) (actual time=79088.099..79088.099 rows=1 loops=1) Sort Key: revenue21.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=811940 read=508351 written=16881 -> Subquery Scan on revenue21 (cost=1190212.42..1190296.34 rows=3730 width=12) (actual time=79066.772..79088.070 rows=1 loops=1) Buffers: shared hit=811940 read=508351 written=16881 -> HashAggregate (cost=1190212.42..1190259.04 rows=3730 width=12) (actual time=79066.770..79088.066 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=811940 read=508351 written=16881 -> Bitmap Heap Scan on lineitem (cost=47561.23..1150912.70 rows=2245698 width=12) (actual time=2974.452..35554.322 rows=2246167 loops=1) Recheck Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=400188 read=259958 written=2420 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46999.81 rows=2245698 width=0) (actual time=2547.195..2547.195 rows=2252538 loops=1) Index Cond: ((l_shipdate >= '1993-10-01'::date) AND (l_shipdate < '1993-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6135 Total runtime: 79139.460 ms (33 rows) drop view revenue21; DROP VIEW COMMIT; COMMIT