BEGIN; BEGIN create or replace view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-05-01' and l_shipdate < date'1994-05-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2358680.82..2363778.50 rows=3748 width=79) (actual time=13403.061..13403.069 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=734731 read=584983 InitPlan 1 (returns $0) -> Aggregate (cost=1170772.34..1170772.35 rows=1 width=8) (actual time=3829.393..3829.393 rows=1 loops=1) Buffers: shared hit=657825 read=1052 -> HashAggregate (cost=1170688.01..1170725.49 rows=3748 width=12) (actual time=3797.069..3819.539 rows=100000 loops=1) Buffers: shared hit=657825 read=1052 -> Bitmap Heap Scan on lineitem (cost=47834.16..1148136.47 rows=2255154 width=12) (actual time=850.204..2484.371 rows=2247412 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=657825 read=1052 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47270.37 rows=2255154 width=0) (actual time=625.423..625.423 rows=2247412 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6138 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.036..25.903 rows=71902 loops=1) Buffers: shared hit=1536 read=423 -> Sort (cost=1187908.47..1187917.84 rows=3748 width=12) (actual time=13370.375..13370.378 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=733195 read=584560 -> Subquery Scan on revenue0 (cost=1187601.66..1187685.99 rows=3748 width=12) (actual time=13354.681..13370.305 rows=1 loops=1) Buffers: shared hit=733195 read=584560 -> HashAggregate (cost=1187601.66..1187648.51 rows=3748 width=12) (actual time=13354.677..13370.299 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=733195 read=584560 -> Bitmap Heap Scan on lineitem (cost=47834.16..1148136.47 rows=2255154 width=12) (actual time=877.454..7425.699 rows=2247412 loops=1) Recheck Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=75370 read=583508 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47270.37 rows=2255154 width=0) (actual time=659.910..659.910 rows=2247412 loops=1) Index Cond: ((l_shipdate >= '1994-05-01'::date) AND (l_shipdate < '1994-07-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 Total runtime: 13411.778 ms (33 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT