BEGIN; BEGIN create or replace view revenue10 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-04-01' and l_shipdate < date'1996-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, revenue10 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue10 ) order by s_suppkey; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=3224751.84..3229849.56 rows=3768 width=79) (actual time=53825.856..53825.859 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue10.supplier_no) Buffers: shared hit=1412015 read=724288 dirtied=1 written=7200 InitPlan 1 (returns $0) -> Aggregate (cost=1603785.20..1603785.21 rows=1 width=8) (actual time=26411.789..26411.789 rows=1 loops=1) Buffers: shared hit=661799 read=405792 written=2922 -> HashAggregate (cost=1603700.42..1603738.10 rows=3768 width=12) (actual time=26368.151..26400.750 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=661799 read=405792 written=2922 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=171658.05..1581090.66 rows=2260976 width=12) (actual time=119.266..24151.067 rows=2246239 loops=1) Recheck Cond: (l_shipdate >= '1996-04-01'::date) Rows Removed by Index Recheck: 37214180 Filter: (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone) Rows Removed by Filter: 20585184 Heap Blocks: lossy=1067543 Buffers: shared hit=661799 read=405792 written=2922 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..171092.80 rows=22792641 width=0) (actual time=118.500..118.500 rows=10686720 loops=1) Index Cond: (l_shipdate >= '1996-04-01'::date) Buffers: shared hit=14 read=34 written=6 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.019..11.549 rows=40980 loops=1) Buffers: shared hit=1105 read=16 -> Sort (cost=1620966.34..1620975.76 rows=3768 width=12) (actual time=53810.226..53810.227 rows=1 loops=1) Sort Key: revenue10.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1410910 read=724272 dirtied=1 written=7200 -> Subquery Scan on revenue10 (cost=1620657.74..1620742.52 rows=3768 width=12) (actual time=53803.808..53810.206 rows=1 loops=1) Buffers: shared hit=1410910 read=724272 dirtied=1 written=7200 -> HashAggregate (cost=1620657.74..1620704.84 rows=3768 width=12) (actual time=53803.808..53810.205 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=1410910 read=724272 dirtied=1 written=7200 -> Bitmap Heap Scan on lineitem (cost=171658.05..1581090.66 rows=2260976 width=12) (actual time=119.961..25171.326 rows=2246239 loops=1) Recheck Cond: (l_shipdate >= '1996-04-01'::date) Rows Removed by Index Recheck: 37214180 Filter: (l_shipdate < '1996-06-30 00:00:00'::timestamp without time zone) Rows Removed by Filter: 20585184 Heap Blocks: lossy=1067543 Buffers: shared hit=749111 read=318480 dirtied=1 written=4278 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..171092.80 rows=22792641 width=0) (actual time=119.195..119.195 rows=10676480 loops=1) Index Cond: (l_shipdate >= '1996-04-01'::date) Buffers: shared hit=13 read=35 Planning time: 2.026 ms Execution time: 53828.564 ms (44 rows) drop view revenue10; DROP VIEW COMMIT; COMMIT