BEGIN; BEGIN create or replace view revenue8 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-01-01' and l_shipdate < date'1996-01-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, revenue8 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue8 ) order by s_suppkey; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=3331074.59..3336172.30 rows=3767 width=79) (actual time=44858.787..44858.789 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue8.supplier_no) Buffers: shared hit=1892627 read=246585 dirtied=1062 written=445 InitPlan 1 (returns $0) -> Aggregate (cost=1656940.82..1656940.83 rows=1 width=8) (actual time=24273.902..24273.903 rows=1 loops=1) Buffers: shared hit=831198 read=237455 written=21 -> HashAggregate (cost=1656856.07..1656893.74 rows=3767 width=12) (actual time=24223.217..24262.811 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=831198 read=237455 written=21 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=189017.71..1634230.88 rows=2262519 width=12) (actual time=118.769..22222.309 rows=2241051 loops=1) Recheck Cond: (l_shipdate >= '1996-01-01'::date) Rows Removed by Index Recheck: 34911122 Filter: (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone) Rows Removed by Filter: 22833480 Heap Blocks: lossy=1068605 Buffers: shared hit=831198 read=237455 written=21 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..188452.08 rows=25107211 width=0) (actual time=118.028..118.028 rows=10696960 loops=1) Index Cond: (l_shipdate >= '1996-01-01'::date) Buffers: shared hit=48 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.028..20.840 rows=69999 loops=1) Buffers: shared hit=1906 -> Sort (cost=1674133.46..1674142.88 rows=3767 width=12) (actual time=44831.113..44831.114 rows=1 loops=1) Sort Key: revenue8.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1890721 read=246585 dirtied=1062 written=445 -> Subquery Scan on revenue8 (cost=1673824.96..1673909.72 rows=3767 width=12) (actual time=44816.545..44831.093 rows=1 loops=1) Buffers: shared hit=1890721 read=246585 dirtied=1062 written=445 -> HashAggregate (cost=1673824.96..1673872.05 rows=3767 width=12) (actual time=44816.543..44831.091 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=1890721 read=246585 dirtied=1062 written=445 -> Bitmap Heap Scan on lineitem (cost=189017.71..1634230.88 rows=2262519 width=12) (actual time=122.715..18389.835 rows=2241051 loops=1) Recheck Cond: (l_shipdate >= '1996-01-01'::date) Rows Removed by Index Recheck: 34911122 Filter: (l_shipdate < '1996-03-31 00:00:00'::timestamp without time zone) Rows Removed by Filter: 22833480 Heap Blocks: lossy=1068605 Buffers: shared hit=1059523 read=9130 dirtied=1062 written=424 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..188452.08 rows=25107211 width=0) (actual time=121.967..121.967 rows=10686720 loops=1) Index Cond: (l_shipdate >= '1996-01-01'::date) Buffers: shared hit=48 Planning time: 1.974 ms Execution time: 44861.073 ms (44 rows) drop view revenue8; DROP VIEW COMMIT; COMMIT