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#55' and p_container = 'WRAP JAR' and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey ); QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=350755.37..350755.39 rows=1 width=4) (actual time=683.784..683.784 rows=1 loops=1) Buffers: shared hit=59622 read=20389 dirtied=36 written=29 -> Nested Loop (cost=130.19..350705.84 rows=19814 width=4) (actual time=0.802..682.888 rows=5100 loops=1) Buffers: shared hit=59622 read=20389 dirtied=36 written=29 -> Index Only Scan using part_p_container_p_brand_p_partkey_idx on part (cost=0.43..7796.57 rows=1974 width=4) (actual time=0.140..22.464 rows=1898 loops=1) Index Cond: ((p_container = 'WRAP JAR'::bpchar) AND (p_brand = 'Brand#55'::bpchar)) Heap Fetches: 1898 Buffers: shared hit=1096 read=777 -> Index Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem (cost=129.76..173.61 rows=10 width=12) (actual time=0.006..0.007 rows=3 loops=1898) Index Cond: ((l_partkey = part.p_partkey) AND (l_quantity < (SubPlan 1))) Buffers: shared hit=12736 SubPlan 1 -> Aggregate (cost=129.19..129.20 rows=1 width=4) (actual time=0.338..0.338 rows=1 loops=1898) Buffers: shared hit=45790 read=19612 dirtied=36 written=29 -> Index Only Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem lineitem_1 (cost=0.56..129.11 rows=31 width=4) (actual time=0.035..0.329 rows=30 loops=1898) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 57515 Buffers: shared hit=45790 read=19612 dirtied=36 written=29 SubPlan 1 -> Aggregate (cost=129.19..129.20 rows=1 width=4) (actual time=0.338..0.338 rows=1 loops=1898) Buffers: shared hit=45790 read=19612 dirtied=36 written=29 -> Index Only Scan using lineitem_l_partkey_l_quantity_l_shipmode_idx on lineitem lineitem_1 (cost=0.56..129.11 rows=31 width=4) (actual time=0.035..0.329 rows=30 loops=1898) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 57515 Buffers: shared hit=45790 read=19612 dirtied=36 written=29 Planning time: 3.377 ms Execution time: 683.978 ms (27 rows) COMMIT; COMMIT