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-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, revenue3 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue3 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2377507.75..2382604.79 rows=3723 width=79) (actual time=20633.870..20633.875 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue3.supplier_no) Buffers: shared hit=728753 read=601189 written=754 InitPlan 1 (returns $0) -> Aggregate (cost=1180181.30..1180181.31 rows=1 width=8) (actual time=10147.932..10147.932 rows=1 loops=1) Buffers: shared hit=379998 read=284170 written=566 -> HashAggregate (cost=1180097.53..1180134.76 rows=3723 width=12) (actual time=10067.284..10137.318 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=379998 read=284170 written=566 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47638.08..1157532.15 rows=2256538 width=12) (actual time=1637.240..7874.550 rows=2245796 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=658034 Buffers: shared hit=379998 read=284170 written=566 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47073.95 rows=2256538 width=0) (actual time=1318.875..1318.875 rows=2266065 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 written=6 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.028..23.127 rows=58899 loops=1) Buffers: shared hit=1606 -> Sort (cost=1197326.15..1197335.46 rows=3723 width=12) (actual time=20604.763..20604.765 rows=1 loops=1) Sort Key: revenue3.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=727147 read=601189 written=754 -> Subquery Scan on revenue3 (cost=1197021.56..1197105.33 rows=3723 width=12) (actual time=20567.270..20604.692 rows=1 loops=1) Buffers: shared hit=727147 read=601189 written=754 -> HashAggregate (cost=1197021.56..1197068.10 rows=3723 width=12) (actual time=20567.267..20604.685 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=727147 read=601189 written=754 -> Bitmap Heap Scan on lineitem (cost=47638.08..1157532.15 rows=2256538 width=12) (actual time=1224.637..7942.295 rows=2245796 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=658034 Buffers: shared hit=347149 read=317019 written=188 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47073.95 rows=2256538 width=0) (actual time=955.613..955.613 rows=2266065 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 written=16 Planning time: 2.486 ms Execution time: 20647.654 ms (38 rows) drop view revenue3; DROP VIEW COMMIT; COMMIT