BEGIN; BEGIN create or replace view revenue11 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-01-01' and l_shipdate < date'1993-01-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, revenue11 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue11 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2359025.20..2364122.77 rows=3758 width=79) (actual time=22017.698..22017.703 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue11.supplier_no) Buffers: shared hit=642962 read=677058 written=17226 InitPlan 1 (returns $0) -> Aggregate (cost=1170930.80..1170930.81 rows=1 width=8) (actual time=7988.870..7988.870 rows=1 loops=1) Buffers: shared hit=403417 read=255857 written=5990 -> HashAggregate (cost=1170846.25..1170883.83 rows=3758 width=12) (actual time=7940.456..7978.556 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=403417 read=255857 written=5990 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47904.10..1148259.39 rows=2258686 width=12) (actual time=1192.498..6042.074 rows=2247367 loops=1) Recheck Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653130 Buffers: shared hit=403417 read=255857 written=5990 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47339.43 rows=2258686 width=0) (actual time=922.450..922.450 rows=2251470 loops=1) Index Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=517 read=5627 written=287 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.021..20.732 rows=53897 loops=1) Buffers: shared hit=1472 -> Sort (cost=1188094.09..1188103.49 rows=3758 width=12) (actual time=21991.637..21991.640 rows=1 loops=1) Sort Key: revenue11.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=641490 read=677058 written=17226 -> Subquery Scan on revenue11 (cost=1187786.39..1187870.95 rows=3758 width=12) (actual time=21946.679..21991.602 rows=1 loops=1) Buffers: shared hit=641490 read=677058 written=17226 -> HashAggregate (cost=1187786.39..1187833.37 rows=3758 width=12) (actual time=21946.678..21991.599 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=641490 read=677058 written=17226 -> Bitmap Heap Scan on lineitem (cost=47904.10..1148259.39 rows=2258686 width=12) (actual time=2100.198..10765.325 rows=2247367 loops=1) Recheck Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653130 Buffers: shared hit=238073 read=421201 written=11236 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47339.43 rows=2258686 width=0) (actual time=1719.913..1719.913 rows=2249543 loops=1) Index Cond: ((l_shipdate >= '1993-01-01'::date) AND (l_shipdate < '1993-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=2 read=6142 Planning time: 2.221 ms Execution time: 22026.473 ms (38 rows) drop view revenue11; DROP VIEW COMMIT; COMMIT