BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-03-01' and l_shipdate < date'1996-03-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361183.68..2366281.22 rows=3756 width=79) (actual time=21904.386..21904.390 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=478727 read=839719 dirtied=584 written=24516 InitPlan 1 (returns $0) -> Aggregate (cost=1172007.38..1172007.39 rows=1 width=8) (actual time=11453.757..11453.757 rows=1 loops=1) Buffers: shared hit=80930 read=577718 dirtied=584 written=24515 -> HashAggregate (cost=1171922.87..1171960.43 rows=3756 width=12) (actual time=11415.464..11443.492 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=80930 read=577718 dirtied=584 written=24515 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47891.55..1149328.74 rows=2259413 width=12) (actual time=1808.474..9607.292 rows=2244430 loops=1) Recheck Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-05-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652517 Buffers: shared hit=80930 read=577718 dirtied=584 written=24515 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47326.70 rows=2259413 width=0) (actual time=1425.508..1425.508 rows=2246637 loops=1) Index Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6131 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.078..13.473 rows=41964 loops=1) Buffers: shared hit=1142 read=8 written=1 -> Sort (cost=1189175.99..1189185.38 rows=3756 width=12) (actual time=21887.029..21887.031 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=477585 read=839711 dirtied=584 written=24515 -> Subquery Scan on revenue5 (cost=1188868.47..1188952.98 rows=3756 width=12) (actual time=21868.984..21886.996 rows=1 loops=1) Buffers: shared hit=477585 read=839711 dirtied=584 written=24515 -> HashAggregate (cost=1188868.47..1188915.42 rows=3756 width=12) (actual time=21868.981..21886.990 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=477585 read=839711 dirtied=584 written=24515 -> Bitmap Heap Scan on lineitem (cost=47891.55..1149328.74 rows=2259413 width=12) (actual time=1694.465..7755.797 rows=2244430 loops=1) Recheck Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-05-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652517 Buffers: shared hit=396655 read=261993 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47326.70 rows=2259413 width=0) (actual time=1310.633..1310.633 rows=2246637 loops=1) Index Cond: ((l_shipdate >= '1996-03-01'::date) AND (l_shipdate < '1996-05-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6131 Planning time: 2.481 ms Execution time: 21926.913 ms (38 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT