BEGIN; BEGIN create or replace view revenue3 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-08-01' and l_shipdate < date'1994-08-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, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2372591.86..2377690.62 rows=3837 width=79) (actual time=15109.234..15109.237 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue3.supplier_no) Buffers: shared hit=674908 read=648742 InitPlan 1 (returns $0) -> Aggregate (cost=1177515.16..1177515.17 rows=1 width=8) (actual time=6544.445..6544.445 rows=1 loops=1) Buffers: shared hit=390386 read=270784 -> HashAggregate (cost=1177428.83..1177467.20 rows=3837 width=12) (actual time=6511.529..6535.077 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=390386 read=270784 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48912.76..1154318.40 rows=2311043 width=12) (actual time=1172.359..4997.457 rows=2245465 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655030 Buffers: shared hit=390386 read=270784 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48335.00 rows=2311043 width=0) (actual time=875.365..875.365 rows=2256875 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-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.038..16.286 rows=47970 loops=1) Buffers: shared hit=1310 -> Sort (cost=1195076.40..1195085.99 rows=3837 width=12) (actual time=15088.505..15088.506 rows=1 loops=1) Sort Key: revenue3.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=673598 read=648742 -> Subquery Scan on revenue3 (cost=1194761.65..1194847.99 rows=3837 width=12) (actual time=15087.592..15088.461 rows=1 loops=1) Buffers: shared hit=673598 read=648742 -> HashAggregate (cost=1194761.65..1194809.62 rows=3837 width=12) (actual time=15087.590..15088.458 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=673598 read=648742 -> Bitmap Heap Scan on lineitem (cost=48912.76..1154318.40 rows=2311043 width=12) (actual time=1165.292..6760.454 rows=2245465 loops=1) Recheck Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=655030 Buffers: shared hit=283212 read=377958 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48335.00 rows=2311043 width=0) (actual time=873.415..873.415 rows=2256875 loops=1) Index Cond: ((l_shipdate >= '1994-08-01'::date) AND (l_shipdate < '1994-10-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6140 Planning time: 2.228 ms Execution time: 15118.512 ms (38 rows) drop view revenue3; DROP VIEW COMMIT; COMMIT