BEGIN; BEGIN create or replace view revenue13 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-04-01' and l_shipdate < date'1993-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, revenue13 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue13 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2383983.69..2389080.59 rows=3713 width=79) (actual time=20171.405..20171.407 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue13.supplier_no) Buffers: shared hit=335992 read=998525 written=38030 InitPlan 1 (returns $0) -> Aggregate (cost=1183412.43..1183412.44 rows=1 width=8) (actual time=10071.330..10071.330 rows=1 loops=1) Buffers: shared hit=131417 read=535591 written=37987 -> HashAggregate (cost=1183328.89..1183366.02 rows=3713 width=12) (actual time=10034.630..10061.286 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=131417 read=535591 written=37987 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47605.67..1160744.40 rows=2258449 width=12) (actual time=1100.940..8109.335 rows=2250488 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660863 Buffers: shared hit=131417 read=535591 written=37987 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47041.06 rows=2258449 width=0) (actual time=804.101..804.101 rows=2276945 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6145 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.030..6.658 rows=17858 loops=1) Buffers: shared hit=387 read=114 -> Sort (cost=1200570.95..1200580.24 rows=3713 width=12) (actual time=20163.006..20163.007 rows=1 loops=1) Sort Key: revenue13.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=335605 read=998411 written=38030 -> Subquery Scan on revenue13 (cost=1200267.26..1200350.80 rows=3713 width=12) (actual time=20158.191..20162.982 rows=1 loops=1) Buffers: shared hit=335605 read=998411 written=38030 -> HashAggregate (cost=1200267.26..1200313.67 rows=3713 width=12) (actual time=20158.190..20162.979 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=335605 read=998411 written=38030 -> Bitmap Heap Scan on lineitem (cost=47605.67..1160744.40 rows=2258449 width=12) (actual time=1127.043..8266.096 rows=2250488 loops=1) Recheck Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=660863 Buffers: shared hit=204188 read=462820 written=43 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47041.06 rows=2258449 width=0) (actual time=874.653..874.653 rows=2276945 loops=1) Index Cond: ((l_shipdate >= '1993-04-01'::date) AND (l_shipdate < '1993-06-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6145 Planning time: 2.830 ms Execution time: 20181.058 ms (38 rows) drop view revenue13; DROP VIEW COMMIT; COMMIT