BEGIN; BEGIN create or replace view revenue6 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1993-12-01' and l_shipdate < date'1993-12-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, revenue6 where s_suppkey = supplier_no and total_revenue = ( select max(total_revenue) from revenue6 ) order by s_suppkey; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Merge Join (cost=2362493.06..2367590.67 rows=3760 width=79) (actual time=19877.062..19877.065 rows=1 loops=1) Merge Cond: (supplier.s_suppkey = revenue6.supplier_no) Buffers: shared hit=529338 read=788471 dirtied=782 written=25250 InitPlan 1 (returns $0) -> Aggregate (cost=1172649.30..1172649.31 rows=1 width=8) (actual time=9384.629..9384.629 rows=1 loops=1) Buffers: shared hit=287708 read=371086 written=919 -> HashAggregate (cost=1172564.70..1172602.30 rows=3760 width=12) (actual time=9346.175..9374.285 rows=100000 loops=1) Group Key: lineitem_1.l_suppkey Buffers: shared hit=287708 read=371086 written=919 -> Bitmap Heap Scan on lineitem lineitem_1 (cost=47954.10..1149936.86 rows=2262784 width=12) (actual time=1184.418..7519.605 rows=2241187 loops=1) Recheck Cond: ((l_shipdate >= '1993-12-01'::date) AND (l_shipdate < '1994-03-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652666 Buffers: shared hit=287708 read=371086 written=919 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47388.40 rows=2262784 width=0) (actual time=883.435..883.435 rows=2247739 loops=1) Index Cond: ((l_shipdate >= '1993-12-01'::date) AND (l_shipdate < '1994-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=3 read=6125 -> Index Scan using pk_supplier on supplier (cost=0.29..4791.49 rows=100000 width=71) (actual time=0.037..3.196 rows=7917 loops=1) Buffers: shared hit=221 -> Sort (cost=1189843.46..1189852.86 rows=3760 width=12) (actual time=19873.145..19873.145 rows=1 loops=1) Sort Key: revenue6.supplier_no Sort Method: quicksort Memory: 25kB Buffers: shared hit=529117 read=788471 dirtied=782 written=25250 -> Subquery Scan on revenue6 (cost=1189535.58..1189620.18 rows=3760 width=12) (actual time=19870.353..19873.113 rows=1 loops=1) Buffers: shared hit=529117 read=788471 dirtied=782 written=25250 -> HashAggregate (cost=1189535.58..1189582.58 rows=3760 width=12) (actual time=19870.352..19873.112 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=529117 read=788471 dirtied=782 written=25250 -> Bitmap Heap Scan on lineitem (cost=47954.10..1149936.86 rows=2262784 width=12) (actual time=1294.602..8465.471 rows=2241187 loops=1) Recheck Cond: ((l_shipdate >= '1993-12-01'::date) AND (l_shipdate < '1994-03-01 00:00:00'::timestamp without time zone)) Heap Blocks: exact=652666 Buffers: shared hit=241409 read=417385 dirtied=782 written=24331 -> Bitmap Index Scan on lineitem_l_shipdate_l_suppkey__idx (cost=0.00..47388.40 rows=2262784 width=0) (actual time=993.130..993.130 rows=2246695 loops=1) Index Cond: ((l_shipdate >= '1993-12-01'::date) AND (l_shipdate < '1994-03-01 00:00:00'::timestamp without time zone)) Buffers: shared hit=1021 read=5107 written=164 Planning time: 2.295 ms Execution time: 19894.947 ms (38 rows) drop view revenue6; DROP VIEW COMMIT; COMMIT