BEGIN; BEGIN create or replace view revenue14 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1997-02-01' and l_shipdate < date'1997-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, revenue14 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue14 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2379416.71..2384515.47 rows=3837 width=79) (actual time=20809.998..20810.001 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue14.supplier_no) Buffers: shared hit=762074 read=566682 dirtied=1 written=17426 InitPlan 1 (returns $0) -> Aggregate (cost=1180904.28..1180904.29 rows=1 width=8) (actual time=10166.076..10166.076 rows=1 loops=1) Buffers: shared hit=322848 read=340511 dirtied=1 written=17117 -> HashAggregate (cost=1180817.94..1180856.31 rows=3837 width=12) (actual time=10098.785..10155.784 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=322848 read=340511 dirtied=1 written=17117 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48968.47..1157645.35 rows=2317259 width=12) (actual time=1396.200..7344.096 rows=2249895 loops=1) Recheck Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657215 Buffers: shared hit=322848 read=340511 dirtied=1 written=17117 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48389.15 rows=2317259 width=0) (actual time=1047.314..1047.314 rows=2265540 loops=1) Index Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6144 written=32 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.035..27.304 rows=74945 loops=1) Buffers: shared hit=2038 -> Sort (cost=1198512.13..1198521.72 rows=3837 width=12) (actual time=20775.253..20775.254 rows=1 loops=1) Sort Key: revenue14.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=760036 read=566682 dirtied=1 written=17426 -> Subquery Scan on revenue14 (cost=1198197.39..1198283.72 rows=3837 width=12) (actual time=20753.692..20775.220 rows=1 loops=1) Buffers: shared hit=760036 read=566682 dirtied=1 written=17426 -> HashAggregate (cost=1198197.39..1198245.35 rows=3837 width=12) (actual time=20753.690..20775.216 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=760036 read=566682 dirtied=1 written=17426 -> Bitmap Heap Scan on lineitem (cost=48968.47..1157645.35 rows=2317259 width=12) (actual time=2098.157..7965.130 rows=2249895 loops=1) Recheck Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Heap Blocks: exact=657215 Buffers: shared hit=437188 read=226171 written=309 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..48389.15 rows=2317259 width=0) (actual time=1613.125..1613.125 rows=2265540 loops=1) Index Cond: ((l_shipdate >= '1997-02-01'::date) AND (l_shipdate < '1997-05-02 00:00:00'::timestamp without time zone)) Buffers: shared read=6144 written=28 Planning time: 3.008 ms Execution time: 20825.548 ms (38 rows) drop view revenue14; DROP VIEW COMMIT; COMMIT