BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-04-01' and l_shipdate < date'1994-04-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2361630.87..2366727.95 rows=3725 width=79) (actual time=17353.682..17353.685 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=629936 read=690823 dirtied=1169 written=464 InitPlan 1 (returns $0) -> Aggregate (cost=1172293.23..1172293.24 rows=1 width=8) (actual time=8104.549..8104.549 rows=1 loops=1) Buffers: shared hit=328689 read=330953 dirtied=542 written=384 -> HashAggregate (cost=1172209.42..1172246.67 rows=3725 width=12) (actual time=8066.231..8094.750 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=328689 read=330953 dirtied=542 written=384 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47524.22..1149778.54 rows=2243088 width=12) (actual time=1080.333..6417.626 rows=2245569 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653508 Buffers: shared hit=328689 read=330953 dirtied=542 written=384 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46963.45 rows=2243088 width=0) (actual time=807.827..807.827 rows=2250325 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.040..21.507 rows=53995 loops=1) Buffers: shared hit=1475 -> Sort (cost=1189337.34..1189346.65 rows=3725 width=12) (actual time=17327.110..17327.111 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=628461 read=690823 dirtied=1169 written=464 -> Subquery Scan on revenue8 (cost=1189032.58..1189116.39 rows=3725 width=12) (actual time=17320.227..17327.082 rows=1 loops=1) Buffers: shared hit=628461 read=690823 dirtied=1169 written=464 -> HashAggregate (cost=1189032.58..1189079.14 rows=3725 width=12) (actual time=17320.226..17327.080 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=628461 read=690823 dirtied=1169 written=464 -> Bitmap Heap Scan on lineitem (cost=47524.22..1149778.54 rows=2243088 width=12) (actual time=1047.262..7445.965 rows=2245569 loops=1) Recheck Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653508 Buffers: shared hit=299772 read=359870 dirtied=627 written=80 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46963.45 rows=2243088 width=0) (actual time=806.553..806.553 rows=2250325 loops=1) Index Cond: ((l_shipdate >= '1994-04-01'::date) AND (l_shipdate < '1994-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6134 Planning time: 2.200 ms Execution time: 17366.152 ms (38 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT