BEGIN; BEGIN EXPLAIN (ANALYZE, BUFFERS) select sum(l_extendedprice) / 7.0 as avg_yearly from lineitem, part where p_partkey = l_partkey and p_brand = 'Brand#11' and p_container = 'WRAP PKG' and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey ); QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=397679.37..397679.38 rows=1 width=4) (actual time=801.244..801.244 rows=1 loops=1) Buffers: shared hit=55184 read=25265 dirtied=47 -> Nested Loop (cost=140.78..397629.73 rows=19855 width=4) (actual time=1.280..800.042 rows=5261 loops=1) Buffers: shared hit=55184 read=25265 dirtied=47 -> Index Only Scan using part_p_container_p_brand_p_partkey_idx on part (cost=0.00..7821.47 rows=1980 width=4) (actual time=0.405..36.359 rows=1918 loops=1) Index Cond: ((p_container = 'WRAP PKG'::bpchar) AND (p_brand = 'Brand#11'::bpchar)) Heap Fetches: 1918 Buffers: shared read=1897 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=140.78..196.77 rows=10 width=12) (actual time=0.007..0.009 rows=3 loops=1918) Index Cond: ((l_partkey = part.p_partkey) AND (l_quantity < (SubPlan 1))) Buffers: shared hit=12971 SubPlan 1 -> Aggregate (cost=140.77..140.78 rows=1 width=4) (actual time=0.384..0.384 rows=1 loops=1918) Buffers: shared hit=42213 read=23368 dirtied=47 -> Index Only Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.00..140.69 rows=31 width=4) (actual time=0.042..0.373 rows=30 loops=1918) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 57638 Buffers: shared hit=42213 read=23368 dirtied=47 SubPlan 1 -> Aggregate (cost=140.77..140.78 rows=1 width=4) (actual time=0.384..0.384 rows=1 loops=1918) Buffers: shared hit=42213 read=23368 dirtied=47 -> Index Only Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=0.00..140.69 rows=31 width=4) (actual time=0.042..0.373 rows=30 loops=1918) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 57638 Buffers: shared hit=42213 read=23368 dirtied=47 Total runtime: 803.709 ms (26 rows) COMMIT; COMMIT