BEGIN; BEGIN create or replace view revenue24 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-11-01' and l_shipdate < date'1994-11-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, revenue24 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue24 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2377507.75..2382604.79 rows=3723 width=79) (actual time=23496.701..23496.706 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue24.supplier_no) Buffers: shared hit=701965 read=629072 written=1474 InitPlan 1 (returns $0) -> Aggregate (cost=1180181.30..1180181.31 rows=1 width=8) (actual time=9267.506..9267.506 rows=1 loops=1) Buffers: shared hit=332148 read=332647 written=1017 -> HashAggregate (cost=1180097.53..1180134.76 rows=3723 width=12) (actual time=9221.200..9256.625 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=332148 read=332647 written=1017 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47638.08..1157532.15 rows=2256538 width=12) (actual time=1274.385..7279.055 rows=2246705 loops=1) Recheck Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658658 Buffers: shared hit=332148 read=332647 written=1017 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47073.95 rows=2256538 width=0) (actual time=967.380..967.380 rows=2267178 loops=1) Index Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6137 written=9 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.030..19.649 rows=52960 loops=1) Buffers: shared hit=1447 -> Sort (cost=1197326.15..1197335.46 rows=3723 width=12) (actual time=23471.599..23471.601 rows=1 loops=1) Sort Key: revenue24.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=700518 read=629072 written=1474 -> Subquery Scan on revenue24 (cost=1197021.56..1197105.33 rows=3723 width=12) (actual time=23450.199..23471.563 rows=1 loops=1) Buffers: shared hit=700518 read=629072 written=1474 -> HashAggregate (cost=1197021.56..1197068.10 rows=3723 width=12) (actual time=23450.197..23471.558 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=700518 read=629072 written=1474 -> Bitmap Heap Scan on lineitem (cost=47638.08..1157532.15 rows=2256538 width=12) (actual time=3037.864..10178.190 rows=2246705 loops=1) Recheck Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=658658 Buffers: shared hit=368370 read=296425 written=457 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47073.95 rows=2256538 width=0) (actual time=2611.776..2611.776 rows=2267178 loops=1) Index Cond: ((l_shipdate >= '1994-11-01'::date) AND (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=1 read=6136 written=3 Planning time: 3.139 ms Execution time: 23511.927 ms (38 rows) drop view revenue24; DROP VIEW COMMIT; COMMIT