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#43' and p_container = 'JUMBO DRUM' and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey ); QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=395669.47..395669.48 rows=1 width=4) (actual time=812.259..812.259 rows=1 loops=1) Buffers: shared hit=74569 read=9856 dirtied=83 written=3 -> Nested Loop (cost=140.78..395620.13 rows=19735 width=4) (actual time=2.644..810.736 rows=5350 loops=1) Buffers: shared hit=74569 read=9856 dirtied=83 written=3 -> Index Only Scan using part_p_container_p_brand_p_partkey_idx on part (cost=0.00..7781.59 rows=1970 width=4) (actual time=0.765..41.557 rows=2022 loops=1) Index Cond: ((p_container = 'JUMBO DRUM'::bpchar) AND (p_brand = 'Brand#43'::bpchar)) Heap Fetches: 2022 Buffers: shared hit=504 read=1477 -> 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.009..0.013 rows=3 loops=2022) Index Cond: ((l_partkey = part.p_partkey) AND (l_quantity < (SubPlan 1))) Buffers: shared hit=13479 SubPlan 1 -> Aggregate (cost=140.77..140.78 rows=1 width=4) (actual time=0.362..0.362 rows=1 loops=2022) Buffers: shared hit=60586 read=8379 dirtied=83 written=3 -> 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.048..0.350 rows=30 loops=2022) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 60554 Buffers: shared hit=60586 read=8379 dirtied=83 written=3 SubPlan 1 -> Aggregate (cost=140.77..140.78 rows=1 width=4) (actual time=0.362..0.362 rows=1 loops=2022) Buffers: shared hit=60586 read=8379 dirtied=83 written=3 -> 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.048..0.350 rows=30 loops=2022) Index Cond: (l_partkey = part.p_partkey) Heap Fetches: 60554 Buffers: shared hit=60586 read=8379 dirtied=83 written=3 Total runtime: 812.569 ms (26 rows) COMMIT; COMMIT