BEGIN; BEGIN create or replace view revenue6 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-09-01' and l_shipdate < date'1995-09-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, revenue6 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue6 ) order by s_suppkey; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=3468931.96..3474029.76 rows=3773 width=79) (actual time=41973.283..41973.286 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue6.supplier_no) Buffers: shared hit=1956315 read=183650 written=146 InitPlan 1 (returns $0) -> Aggregate (cost=1725856.89..1725856.90 rows=1 width=8) (actual time=18716.903..18716.903 rows=1 loops=1) Buffers: shared hit=1061745 read=6908 written=1 -> HashAggregate (cost=1725772.00..1725809.73 rows=3773 width=12) (actual time=18675.132..18705.971 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=1061745 read=6908 written=1 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=211979.20..1703113.68 rows=2265832 width=12) (actual time=118.980..16940.681 rows=2247643 loops=1) Recheck Cond: (l_shipdate >= '1995-09-01'::date) Rows Removed by Index Recheck: 31901152 Filter: (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone) Rows Removed by Filter: 25896584 Heap Blocks: lossy=1068605 Buffers: shared hit=1061745 read=6908 written=1 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..211412.74 rows=28168632 width=0) (actual time=118.232..118.232 rows=10693120 loops=1) Index Cond: (l_shipdate >= '1995-09-01'::date) Buffers: shared hit=23 read=25 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.026..27.620 rows=97885 loops=1) Buffers: shared hit=2659 -> Sort (cost=1743074.77..1743084.21 rows=3773 width=12) (actual time=41936.110..41936.111 rows=1 loops=1) Sort Key: revenue6.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1953656 read=183650 written=146 -> Subquery Scan on revenue6 (cost=1742765.74..1742850.63 rows=3773 width=12) (actual time=41920.919..41936.090 rows=1 loops=1) Buffers: shared hit=1953656 read=183650 written=146 -> HashAggregate (cost=1742765.74..1742812.90 rows=3773 width=12) (actual time=41920.918..41936.087 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=1953656 read=183650 written=146 -> Bitmap Heap Scan on lineitem (cost=211979.20..1703113.68 rows=2265832 width=12) (actual time=124.771..21117.153 rows=2247643 loops=1) Recheck Cond: (l_shipdate >= '1995-09-01'::date) Rows Removed by Index Recheck: 31901152 Filter: (l_shipdate < '1995-11-30 00:00:00'::timestamp without time zone) Rows Removed by Filter: 25896584 Heap Blocks: lossy=1068605 Buffers: shared hit=891911 read=176742 written=145 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..211412.74 rows=28168632 width=0) (actual time=124.022..124.022 rows=10686720 loops=1) Index Cond: (l_shipdate >= '1995-09-01'::date) Buffers: shared hit=13 read=35 Planning time: 1.908 ms Execution time: 41975.545 ms (44 rows) drop view revenue6; DROP VIEW COMMIT; COMMIT