BEGIN; BEGIN create or replace view revenue23 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1994-01-01' and l_shipdate < date'1994-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, revenue23 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue23 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2363913.46..2369011.42 rows=3767 width=79) (actual time=88641.302..88641.306 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue23.supplier_no) Buffers: shared hit=930302 read=388331 written=217 InitPlan 1 (returns $0) -> Aggregate (cost=1173348.19..1173348.20 rows=1 width=8) (actual time=38454.587..38454.587 rows=1 loops=1) Buffers: shared hit=565489 read=93520 -> HashAggregate (cost=1173263.43..1173301.10 rows=3767 width=12) (actual time=38383.998..38442.227 rows=100000 loops=1) Buffers: shared hit=565489 read=93520 -> Bitmap Heap Scan on lineitem (cost=48011.03..1150605.67 rows=2265776 width=12) (actual time=4558.105..33569.734 rows=2244196 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=565489 read=93520 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47444.59 rows=2265776 width=0) (actual time=4149.521..4149.521 rows=2248683 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=4606 read=1524 -> Index Scan using pk_supplier on supplier (cost=0.00..4791.46 rows=100000 width=71) (actual time=1.127..34.082 rows=21986 loops=1) Buffers: shared hit=613 read=1 -> Sort (cost=1190565.26..1190574.67 rows=3767 width=12) (actual time=88603.589..88603.590 rows=1 loops=1) Sort Key: revenue23.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=929689 read=388330 written=217 -> Subquery Scan on revenue23 (cost=1190256.75..1190341.51 rows=3767 width=12) (actual time=88584.543..88603.540 rows=1 loops=1) Buffers: shared hit=929689 read=388330 written=217 -> HashAggregate (cost=1190256.75..1190303.84 rows=3767 width=12) (actual time=88584.540..88603.535 rows=1 loops=1) Filter: (sum((public.lineitem.l_extendedprice * (1::double precision - public.lineitem.l_discount))) = $0) Rows Removed by Filter: 99999 Buffers: shared hit=929689 read=388330 written=217 -> Bitmap Heap Scan on lineitem (cost=48011.03..1150605.67 rows=2265776 width=12) (actual time=2868.002..45015.627 rows=2244196 loops=1) Recheck Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=364200 read=294810 written=217 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47444.59 rows=2265776 width=0) (actual time=2482.006..2482.006 rows=2248683 loops=1) Index Cond: ((l_shipdate >= '1994-01-01'::date) AND (l_shipdate < '1994-04-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6128 Total runtime: 88658.418 ms (33 rows) drop view revenue23; DROP VIEW COMMIT; COMMIT