BEGIN; BEGIN create or replace view revenue4 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-06-01' and l_shipdate < date'1994-06-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, revenue4 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue4 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2366549.78..2371648.10 rows=3808 width=79) (actual time=18794.783..18794.788 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue4.supplier_no) Buffers: shared hit=834401 read=486689 dirtied=270 written=1252 InitPlan 1 (returns $0) -> Aggregate (cost=1174562.05..1174562.06 rows=1 width=8) (actual time=10047.607..10047.607 rows=1 loops=1) Buffers: shared hit=312651 read=347441 written=30 -> HashAggregate (cost=1174476.37..1174514.45 rows=3808 width=12) (actual time=9986.597..10037.555 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=312651 read=347441 written=30 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48585.72..1151544.51 rows=2293186 width=12) (actual time=1394.097..7583.059 rows=2245555 loops=1) Recheck Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653952 Buffers: shared hit=312651 read=347441 written=30 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48012.43 rows=2293186 width=0) (actual time=1037.438..1037.438 rows=2252626 loops=1) Index Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.035..12.631 rows=32993 loops=1) Buffers: shared hit=906 -> Sort (cost=1191987.42..1191996.94 rows=3808 width=12) (actual time=18778.959..18778.961 rows=1 loops=1) Sort Key: revenue4.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=833495 read=486689 dirtied=270 written=1252 -> Subquery Scan on revenue4 (cost=1191675.27..1191760.95 rows=3808 width=12) (actual time=18778.494..18778.928 rows=1 loops=1) Buffers: shared hit=833495 read=486689 dirtied=270 written=1252 -> HashAggregate (cost=1191675.27..1191722.87 rows=3808 width=12) (actual time=18778.493..18778.926 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=833495 read=486689 dirtied=270 written=1252 -> Bitmap Heap Scan on lineitem (cost=48585.72..1151544.51 rows=2293186 width=12) (actual time=1279.410..6602.665 rows=2245555 loops=1) Recheck Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=653952 Buffers: shared hit=520844 read=139248 dirtied=270 written=1222 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48012.43 rows=2293186 width=0) (actual time=975.054..975.054 rows=2252601 loops=1) Index Cond: ((l_shipdate >= '1994-06-01'::date) AND (l_shipdate < '1994-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=342 read=5798 written=261 Planning time: 2.821 ms Execution time: 18812.295 ms (38 rows) drop view revenue4; DROP VIEW COMMIT; COMMIT