BEGIN; BEGIN create or replace view revenue2 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1995-02-01' and l_shipdate < date'1995-02-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, revenue2 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue2 ) order by s_suppkey; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=3720970.88..3726069.12 rows=3803 width=79) (actual time=48952.221..48952.224 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue2.supplier_no) Buffers: shared hit=1183203 read=962766 dirtied=1057 written=7472 InitPlan 1 (returns $0) -> Aggregate (cost=1851780.45..1851780.46 rows=1 width=8) (actual time=23436.638..23436.638 rows=1 loops=1) Buffers: shared hit=595172 read=476671 written=266 -> HashAggregate (cost=1851694.88..1851732.91 rows=3803 width=12) (actual time=23390.285..23425.502 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=595172 read=476671 written=266 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=252810.03..1828783.51 rows=2291137 width=12) (actual time=119.924..21297.823 rows=2249966 loops=1) Recheck Cond: (l_shipdate >= '1995-02-01'::date) Rows Removed by Index Recheck: 26606629 Filter: (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone) Rows Removed by Filter: 31189231 Heap Blocks: lossy=1071795 Buffers: shared hit=595172 read=476671 written=266 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..252237.25 rows=33611899 width=0) (actual time=119.153..119.153 rows=10728960 loops=1) Index Cond: (l_shipdate >= '1995-02-01'::date) Buffers: shared hit=13 read=35 written=1 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.026..25.543 rows=83967 loops=1) Buffers: shared hit=2283 -> Sort (cost=1869190.12..1869199.63 rows=3803 width=12) (actual time=48918.423..48918.423 rows=1 loops=1) Sort Key: revenue2.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1180920 read=962766 dirtied=1057 written=7472 -> Subquery Scan on revenue2 (cost=1868878.41..1868963.98 rows=3803 width=12) (actual time=48894.669..48918.405 rows=1 loops=1) Buffers: shared hit=1180920 read=962766 dirtied=1057 written=7472 -> HashAggregate (cost=1868878.41..1868925.95 rows=3803 width=12) (actual time=48894.668..48918.403 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=1180920 read=962766 dirtied=1057 written=7472 -> Bitmap Heap Scan on lineitem (cost=252810.03..1828783.51 rows=2291137 width=12) (actual time=121.503..23302.219 rows=2249966 loops=1) Recheck Cond: (l_shipdate >= '1995-02-01'::date) Rows Removed by Index Recheck: 26606629 Filter: (l_shipdate < '1995-05-02 00:00:00'::timestamp without time zone) Rows Removed by Filter: 31189231 Heap Blocks: lossy=1071795 Buffers: shared hit=585748 read=486095 dirtied=1057 written=7206 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey_brin_idx (cost=0.00..252237.25 rows=33611899 width=0) (actual time=120.728..120.728 rows=10718720 loops=1) Index Cond: (l_shipdate >= '1995-02-01'::date) Buffers: shared hit=13 read=35 Planning time: 2.253 ms Execution time: 48954.861 ms (44 rows) drop view revenue2; DROP VIEW COMMIT; COMMIT