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#51' and p_container = 'MED BOX' and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey ); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=116372.75..116372.76 rows=1 width=4) (actual time=214.716..214.716 rows=1 loops=1) Buffers: shared hit=71407 read=7112 dirtied=68 written=93 -> Nested Loop (cost=83.11..116321.63 rows=20446 width=4) (actual time=1.643..213.548 rows=5185 loops=1) Buffers: shared hit=71407 read=7112 dirtied=68 written=93 -> Bitmap Heap Scan on part (cost=73.35..6743.98 rows=2041 width=4) (actual time=1.278..35.989 rows=1959 loops=1) Recheck Cond: ((p_container = 'MED BOX'::bpchar) AND (p_brand = 'Brand#51'::bpchar)) Heap Blocks: exact=1922 Buffers: shared read=1937 written=25 -> Bitmap Index Scan on part_p_container_p_brand_p_partkey_idx (cost=0.00..72.84 rows=2041 width=0) (actual time=0.941..0.941 rows=1959 loops=1) Index Cond: ((p_container = 'MED BOX'::bpchar) AND (p_brand = 'Brand#51'::bpchar)) Buffers: shared read=15 -> Index Scan using lineitem_l_partkey_l_quantity_idx on lineitem (cost=9.76..53.59 rows=10 width=12) (actual time=0.017..0.041 rows=3 loops=1959) Index Cond: ((l_partkey = part.p_partkey) AND (l_quantity < (SubPlan 1))) Buffers: shared hit=10622 read=2425 written=28 SubPlan 1 -> Aggregate (cost=9.19..9.20 rows=1 width=4) (actual time=0.047..0.047 rows=1 loops=1959) Buffers: shared hit=60785 read=2750 dirtied=68 written=40 -> Index Only Scan using lineitem_l_partkey_l_quantity_idx on lineitem lineitem_1 (cost=0.56..9.11 rows=31 width=4) (actual time=0.026..0.041 rows=30 loops=1959) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 258 Buffers: shared hit=60785 read=2750 dirtied=68 written=40 SubPlan 1 -> Aggregate (cost=9.19..9.20 rows=1 width=4) (actual time=0.047..0.047 rows=1 loops=1959) Buffers: shared hit=60785 read=2750 dirtied=68 written=40 -> Index Only Scan using lineitem_l_partkey_l_quantity_idx on lineitem lineitem_1 (cost=0.56..9.11 rows=31 width=4) (actual time=0.026..0.041 rows=30 loops=1959) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 258 Buffers: shared hit=60785 read=2750 dirtied=68 written=40 Planning time: 2.708 ms Execution time: 214.876 ms (30 rows) COMMIT; COMMIT