BEGIN; BEGIN create or replace view revenue27 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-05-01' and l_shipdate < date'1993-05-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, revenue27 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue27 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2374866.46..2379964.54 rows=3792 width=79) (actual time=22544.982..22544.986 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue27.supplier_no) Buffers: shared hit=774979 read=553246 written=209 InitPlan 1 (returns $0) -> Aggregate (cost=1178723.59..1178723.60 rows=1 width=8) (actual time=10652.542..10652.542 rows=1 loops=1) Buffers: shared hit=388781 read=274191 written=165 -> HashAggregate (cost=1178638.27..1178676.19 rows=3792 width=12) (actual time=10608.931..10641.723 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=388781 read=274191 written=165 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48470.42..1155713.53 rows=2292474 width=12) (actual time=1850.966..8535.659 rows=2248763 loops=1) Recheck Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656831 Buffers: shared hit=388781 read=274191 written=165 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47897.31 rows=2292474 width=0) (actual time=1414.991..1414.991 rows=2262135 loops=1) Index Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6140 written=3 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.096..35.675 rows=83935 loops=1) Buffers: shared hit=2281 -> Sort (cost=1196142.56..1196152.04 rows=3792 width=12) (actual time=22500.850..22500.852 rows=1 loops=1) Sort Key: revenue27.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=772698 read=553246 written=209 -> Subquery Scan on revenue27 (cost=1195831.83..1195917.15 rows=3792 width=12) (actual time=22497.462..22500.813 rows=1 loops=1) Buffers: shared hit=772698 read=553246 written=209 -> HashAggregate (cost=1195831.83..1195879.23 rows=3792 width=12) (actual time=22497.460..22500.810 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=772698 read=553246 written=209 -> Bitmap Heap Scan on lineitem (cost=48470.42..1155713.53 rows=2292474 width=12) (actual time=1591.054..9226.707 rows=2248763 loops=1) Recheck Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=656831 Buffers: shared hit=383917 read=279055 written=44 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47897.31 rows=2292474 width=0) (actual time=1270.536..1270.536 rows=2262135 loops=1) Index Cond: ((l_shipdate >= '1993-05-01'::date) AND (l_shipdate < '1993-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6141 written=2 Planning time: 4.730 ms Execution time: 22558.357 ms (38 rows) drop view revenue27; DROP VIEW COMMIT; COMMIT