BEGIN; BEGIN create or replace view revenue18 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-06-01' and l_shipdate < date'1996-06-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, revenue18 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue18 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2386793.16..2391890.82 rows=3764 width=79) (actual time=18752.014..18752.018 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue18.supplier_no) Buffers: shared hit=891644 read=440832 written=2957 InitPlan 1 (returns $0) -> Aggregate (cost=1184700.00..1184700.01 rows=1 width=8) (actual time=10183.566..10183.566 rows=1 loops=1) Buffers: shared hit=390963 read=275110 written=226 -> HashAggregate (cost=1184615.31..1184652.95 rows=3764 width=12) (actual time=10140.999..10173.058 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=390963 read=275110 written=226 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=48257.29..1161722.90 rows=2289241 width=12) (actual time=2425.169..8376.811 rows=2243514 loops=1) Recheck Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659941 Buffers: shared hit=390963 read=275110 written=226 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47684.98 rows=2289241 width=0) (actual time=2035.061..2035.061 rows=2272500 loops=1) Index Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6132 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.029..4.914 rows=11829 loops=1) Buffers: shared hit=330 -> Sort (cost=1202092.85..1202102.26 rows=3764 width=12) (actual time=18745.848..18745.850 rows=1 loops=1) Sort Key: revenue18.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=891314 read=440832 written=2957 -> Subquery Scan on revenue18 (cost=1201784.62..1201869.31 rows=3764 width=12) (actual time=18703.748..18745.808 rows=1 loops=1) Buffers: shared hit=891314 read=440832 written=2957 -> HashAggregate (cost=1201784.62..1201831.67 rows=3764 width=12) (actual time=18703.746..18745.803 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=891314 read=440832 written=2957 -> Bitmap Heap Scan on lineitem (cost=48257.29..1161722.90 rows=2289241 width=12) (actual time=1149.267..6283.820 rows=2243514 loops=1) Recheck Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=659941 Buffers: shared hit=500351 read=165722 written=2731 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47684.98 rows=2289241 width=0) (actual time=895.465..895.465 rows=2272418 loops=1) Index Cond: ((l_shipdate >= '1996-06-01'::date) AND (l_shipdate < '1996-08-30 00:00:00'::timestamp without time zone)) Buffers: shared hit=859 read=5273 written=519 Planning time: 2.538 ms Execution time: 18764.011 ms (38 rows) drop view revenue18; DROP VIEW COMMIT; COMMIT