BEGIN; BEGIN create or replace view revenue19 (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, revenue19 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue19 ) order by s_suppkey; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2358866.27..2363963.23 rows=3717 width=79) (actual time=26555.420..26555.426 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue19.supplier_no) Buffers: shared hit=595190 read=725818 written=9341 InitPlan 1 (returns $0) -> Aggregate (cost=1170936.95..1170936.96 rows=1 width=8) (actual time=13377.283..13377.283 rows=1 loops=1) Buffers: shared hit=260037 read=399448 written=9341 -> HashAggregate (cost=1170853.32..1170890.49 rows=3717 width=12) (actual time=13310.370..13366.281 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=260037 read=399448 written=9341 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47401.82..1148491.12 rows=2236220 width=12) (actual time=2433.756..10517.401 rows=2247462 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=653341 Buffers: shared hit=260037 read=399448 written=9341 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46842.76 rows=2236220 width=0) (actual time=1899.679..1899.679 rows=2252406 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 hit=205 read=5939 written=137 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.052..31.275 rows=74945 loops=1) Buffers: shared hit=2038 -> Sort (cost=1187929.02..1187938.31 rows=3717 width=12) (actual time=26516.261..26516.263 rows=1 loops=1) Sort Key: revenue19.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=593152 read=725818 written=9341 -> Subquery Scan on revenue19 (cost=1187624.97..1187708.60 rows=3717 width=12) (actual time=26489.486..26516.226 rows=1 loops=1) Buffers: shared hit=593152 read=725818 written=9341 -> HashAggregate (cost=1187624.97..1187671.43 rows=3717 width=12) (actual time=26489.483..26516.221 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=593152 read=725818 written=9341 -> Bitmap Heap Scan on lineitem (cost=47401.82..1148491.12 rows=2236220 width=12) (actual time=2367.935..10263.300 rows=2247462 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=653341 Buffers: shared hit=333115 read=326370 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46842.76 rows=2236220 width=0) (actual time=1863.883..1863.883 rows=2252036 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 Planning time: 4.343 ms Execution time: 26570.638 ms (38 rows) drop view revenue19; DROP VIEW COMMIT; COMMIT