diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index 8d24902..48b21cb 100644
*** a/src/backend/optimizer/path/costsize.c
--- b/src/backend/optimizer/path/costsize.c
*************** final_cost_hashjoin(PlannerInfo *root, H
*** 2661,2685 ****
  	else
  	{
  		/*
- 		 * The number of tuple comparisons needed is the number of outer
- 		 * tuples times the typical number of tuples in a hash bucket, which
- 		 * is the inner relation size times its bucketsize fraction.  At each
- 		 * one, we need to evaluate the hashjoin quals.  But actually,
- 		 * charging the full qual eval cost at each tuple is pessimistic,
- 		 * since we don't evaluate the quals unless the hash values match
- 		 * exactly.  For lack of a better idea, halve the cost estimate to
- 		 * allow for that.
- 		 */
- 		startup_cost += hash_qual_cost.startup;
- 		run_cost += hash_qual_cost.per_tuple * outer_path_rows *
- 			clamp_row_est(inner_path_rows * innerbucketsize) * 0.5;
- 
- 		/*
  		 * Get approx # tuples passing the hashquals.  We use
  		 * approx_tuple_count here because we need an estimate done with
  		 * JOIN_INNER semantics.
  		 */
  		hashjointuples = approx_tuple_count(root, &path->jpath, hashclauses);
  	}
  
  	/*
--- 2661,2692 ----
  	else
  	{
  		/*
  		 * Get approx # tuples passing the hashquals.  We use
  		 * approx_tuple_count here because we need an estimate done with
  		 * JOIN_INNER semantics.
  		 */
  		hashjointuples = approx_tuple_count(root, &path->jpath, hashclauses);
+ 
+ 		/*
+ 		 * We assume that the hash equality operators will be applied to twice
+ 		 * as many join pairs as actually pass the hashquals, that is there's
+ 		 * about one hash-value collision per tuple.  This is probably a
+ 		 * substantial overestimate, but it seems wise to be conservative.
+ 		 * Lacking any good model of the effectiveness of the hash functions,
+ 		 * it's hard to do much better than a constant ratio.  (XXX perhaps we
+ 		 * ought to charge more than this for very large relations, since the
+ 		 * hash values are only 32 bits wide and hence will suffer
+ 		 * proportionally more collisions when there are many rows.)
+ 		 *
+ 		 * Note that we don't charge anything for visiting hash bucket entries
+ 		 * that don't have a matching hash value.  The cost per skipped bucket
+ 		 * entry is not really zero, but it's a lot smaller than the cost of
+ 		 * qual eval, so we ignore it.  If you like you can think of the
+ 		 * probable overestimate of the hash qual cost as partially accounting
+ 		 * for this.
+ 		 */
+ 		startup_cost += hash_qual_cost.startup;
+ 		run_cost += hash_qual_cost.per_tuple * hashjointuples * 2.0;
  	}
  
  	/*
