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 >= '1995-06-01' and l_shipdate < date'1995-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2356513.93..2361611.26 rows=3724 width=79) (actual time=13250.031..13250.035 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=737926 read=581240 InitPlan 1 (returns $0) -> Aggregate (cost=1169771.05..1169771.06 rows=1 width=8) (actual time=3722.442..3722.442 rows=1 loops=1) Buffers: shared hit=657419 read=1202 -> HashAggregate (cost=1169687.26..1169724.50 rows=3724 width=12) (actual time=3692.192..3712.721 rows=100000 loops=1) Buffers: shared hit=657419 read=1202 -> Bitmap Heap Scan on lineitem (cost=47375.78..1147352.67 rows=2233459 width=12) (actual time=802.616..2492.719 rows=2246437 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=657419 read=1202 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46817.42 rows=2233459 width=0) (actual time=582.848..582.848 rows=2246437 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=6135 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=0.066..28.349 rows=70652 loops=1) Buffers: shared hit=1498 read=425 -> Sort (cost=1186742.87..1186752.18 rows=3724 width=12) (actual time=13215.192..13215.193 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=736428 read=580815 -> Subquery Scan on revenue0 (cost=1186438.20..1186521.99 rows=3724 width=12) (actual time=13197.981..13215.141 rows=1 loops=1) Buffers: shared hit=736428 read=580815 -> HashAggregate (cost=1186438.20..1186484.75 rows=3724 width=12) (actual time=13197.980..13215.137 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=736428 read=580815 -> Bitmap Heap Scan on lineitem (cost=47375.78..1147352.67 rows=2233459 width=12) (actual time=895.239..7806.618 rows=2246437 loops=1) Recheck Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=79009 read=579613 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46817.42 rows=2233459 width=0) (actual time=675.941..675.941 rows=2246437 loops=1) Index Cond: ((l_shipdate >= '1995-06-01'::date) AND (l_shipdate < '1995-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6136 Total runtime: 13258.874 ms (33 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT