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-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=3803335.63..3808432.68 rows=3723 width=79) (actual time=54399.286..54399.289 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=5733 read=2128756 InitPlan 1 (returns $0) -> Aggregate (cost=1893188.03..1893188.04 rows=1 width=8) (actual time=25098.388..25098.388 rows=1 loops=1) Buffers: shared hit=107 read=1066414 -> HashAggregate (cost=1893104.26..1893141.49 rows=3723 width=12) (actual time=25062.259..25087.503 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=107 read=1066414 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=268575.07..1870786.33 rows=2231793 width=12) (actual time=118.978..22936.325 rows=2247143 loops=1) Recheck Cond: (l_shipdate >= '1994-11-01'::date) Rows Removed by Index Recheck: 24308422 Filter: (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone) Rows Removed by Filter: 33490104 Heap Blocks: lossy=1066473 Buffers: shared hit=107 read=1066414 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..268017.13 rows=35715884 width=0) (actual time=118.172..118.172 rows=10664960 loops=1) Index Cond: (l_shipdate >= '1994-11-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.017..21.123 rows=52960 loops=1) Buffers: shared hit=149 read=1298 -> Sort (cost=1910147.30..1910156.60 rows=3723 width=12) (actual time=54372.847..54372.848 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=5584 read=2127458 -> Subquery Scan on revenue0 (cost=1909842.71..1909926.48 rows=3723 width=12) (actual time=54363.702..54372.823 rows=1 loops=1) Buffers: shared hit=5584 read=2127458 -> HashAggregate (cost=1909842.71..1909889.25 rows=3723 width=12) (actual time=54363.701..54372.821 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=5584 read=2127458 -> Bitmap Heap Scan on lineitem (cost=268575.07..1870786.33 rows=2231793 width=12) (actual time=119.066..27010.927 rows=2247143 loops=1) Recheck Cond: (l_shipdate >= '1994-11-01'::date) Rows Removed by Index Recheck: 24308422 Filter: (l_shipdate < '1995-01-30 00:00:00'::timestamp without time zone) Rows Removed by Filter: 33490104 Heap Blocks: lossy=1066473 Buffers: shared hit=5477 read=1061044 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..268017.13 rows=35715884 width=0) (actual time=118.255..118.255 rows=10664960 loops=1) Index Cond: (l_shipdate >= '1994-11-01'::date) Buffers: shared hit=12 read=36 Planning time: 2.106 ms Execution time: 54400.977 ms (44 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT