BEGIN; BEGIN create or replace view revenue5 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-02-01' and l_shipdate < date'1993-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, revenue5 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue5 ) order by s_suppkey; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=4001070.80..4006168.75 rows=3783 width=79) (actual time=40222.731..40222.734 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue5.supplier_no) Buffers: shared hit=1162472 read=974086 InitPlan 1 (returns $0) -> Aggregate (cost=1991912.04..1991912.05 rows=1 width=8) (actual time=19808.245..19808.245 rows=1 loops=1) Buffers: shared hit=702938 read=364605 -> HashAggregate (cost=1991826.92..1991864.75 rows=3783 width=12) (actual time=19767.887..19797.292 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=702938 read=364605 -> Seq Scan on lineitem lineitem_1 (cost=0.00..1969131.44 rows=2269548 width=12) (actual time=0.017..17966.257 rows=2250213 loops=1) Filter: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 57795390 Buffers: shared hit=702938 read=364605 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.035..15.030 rows=53897 loops=1) Buffers: shared hit=1466 read=6 -> Sort (cost=2009158.46..2009167.92 rows=3783 width=12) (actual time=40202.267..40202.268 rows=1 loops=1) Sort Key: revenue5.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=1161006 read=974080 -> Subquery Scan on revenue5 (cost=2008848.53..2008933.65 rows=3783 width=12) (actual time=40180.716..40202.246 rows=1 loops=1) Buffers: shared hit=1161006 read=974080 -> HashAggregate (cost=2008848.53..2008895.82 rows=3783 width=12) (actual time=40180.715..40202.243 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=1161006 read=974080 -> Seq Scan on lineitem (cost=0.00..1969131.44 rows=2269548 width=12) (actual time=0.014..18491.907 rows=2250213 loops=1) Filter: ((l_shipdate >= '1993-02-01'::date) AND (l_shipdate < '1993-05-02 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 57795390 Buffers: shared hit=458068 read=609475 Planning time: 2.023 ms Execution time: 40224.930 ms (32 rows) drop view revenue5; DROP VIEW COMMIT; COMMIT