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 >= '1996-09-01' and l_shipdate < date'1996-09-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=2387760.01..2392857.91 rows=3780 width=79) (actual time=22851.244..22851.250 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue13.supplier_no) Buffers: shared hit=670584 read=663918 written=911 InitPlan 1 (returns $0) -> Aggregate (cost=1185156.40..1185156.41 rows=1 width=8) (actual time=11095.861..11095.861 rows=1 loops=1) Buffers: shared hit=352859 read=313465 written=461 -> HashAggregate (cost=1185071.35..1185109.15 rows=3780 width=12) (actual time=11053.855..11085.711 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=352859 read=313465 written=461 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48401.70..1162108.29 rows=2296306 width=12) (actual time=2981.050..9236.280 rows=2248899 loops=1) Recheck Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660181 Buffers: shared hit=352859 read=313465 written=461 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47827.62 rows=2296306 width=0) (actual time=2642.005..2642.005 rows=2276092 loops=1) Index Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6143 written=9 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.039..27.270 rows=67992 loops=1) Buffers: shared hit=1854 -> Sort (cost=1202603.31..1202612.76 rows=3780 width=12) (actual time=22817.179..22817.182 rows=1 loops=1) Sort Key: revenue13.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=668730 read=663918 written=911 -> Subquery Scan on revenue13 (cost=1202293.65..1202378.70 rows=3780 width=12) (actual time=22797.709..22817.150 rows=1 loops=1) Buffers: shared hit=668730 read=663918 written=911 -> HashAggregate (cost=1202293.65..1202340.90 rows=3780 width=12) (actual time=22797.707..22817.146 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=668730 read=663918 written=911 -> Bitmap Heap Scan on lineitem (cost=48401.70..1162108.29 rows=2296306 width=12) (actual time=1724.246..9749.993 rows=2248899 loops=1) Recheck Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660181 Buffers: shared hit=315871 read=350453 written=450 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47827.62 rows=2296306 width=0) (actual time=1366.434..1366.434 rows=2276092 loops=1) Index Cond: ((l_shipdate >= '1996-09-01'::date) AND (l_shipdate < '1996-11-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6143 written=2 Planning time: 3.229 ms Execution time: 22862.548 ms (38 rows) drop view revenue13; DROP VIEW COMMIT; COMMIT