BEGIN; BEGIN create or replace view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-10-01' and l_shipdate < date'1996-10-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, revenue0 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue0 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2356440.47..2361537.39 rows=3715 width=79) (actual time=16329.994..16329.998 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue0.supplier_no) Buffers: shared hit=324222 read=995082 InitPlan 1 (returns $0) -> Aggregate (cost=1169736.60..1169736.61 rows=1 width=8) (actual time=6174.592..6174.592 rows=1 loops=1) Buffers: shared hit=318690 read=340035 -> HashAggregate (cost=1169653.01..1169690.16 rows=3715 width=12) (actual time=6143.966..6164.748 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=318690 read=340035 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47355.71..1147324.09 rows=2232892 width=12) (actual time=841.287..4745.836 rows=2247361 loops=1) Recheck Cond: ((l_shipdate >= '1996-10-01'::date) AND (l_shipdate < '1996-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652586 Buffers: shared hit=318690 read=340035 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46797.49 rows=2232892 width=0) (actual time=623.468..623.468 rows=2247361 loops=1) Index Cond: ((l_shipdate >= '1996-10-01'::date) AND (l_shipdate < '1996-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.053..27.375 rows=67992 loops=1) Buffers: shared hit=753 read=1101 -> Sort (cost=1186703.57..1186712.86 rows=3715 width=12) (actual time=16296.493..16296.495 rows=1 loops=1) Sort Key: revenue0.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=323469 read=993981 -> Subquery Scan on revenue0 (cost=1186399.70..1186483.29 rows=3715 width=12) (actual time=16281.860..16296.447 rows=1 loops=1) Buffers: shared hit=323469 read=993981 -> HashAggregate (cost=1186399.70..1186446.14 rows=3715 width=12) (actual time=16281.859..16296.446 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=323469 read=993981 -> Bitmap Heap Scan on lineitem (cost=47355.71..1147324.09 rows=2232892 width=12) (actual time=992.274..8350.260 rows=2247361 loops=1) Recheck Cond: ((l_shipdate >= '1996-10-01'::date) AND (l_shipdate < '1996-12-30 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652586 Buffers: shared hit=4779 read=653946 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..46797.49 rows=2232892 width=0) (actual time=773.487..773.487 rows=2247361 loops=1) Index Cond: ((l_shipdate >= '1996-10-01'::date) AND (l_shipdate < '1996-12-30 00:00:00'::timestamp without time zone)) Buffers: shared read=6139 Planning time: 4.135 ms Execution time: 16335.600 ms (38 rows) drop view revenue0; DROP VIEW COMMIT; COMMIT