diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 6e491bb..b875d5d 100644
*** a/src/backend/utils/adt/selfuncs.c
--- b/src/backend/utils/adt/selfuncs.c
*************** eqjoinsel_semi(Oid operator,
*** 2603,2610 ****
  		 *
  		 * Crude as the above is, it's completely useless if we don't have
  		 * reliable ndistinct values for both sides.  Hence, if either nd1 or
! 		 * nd2 is default, punt and assume half of the uncertain rows have
! 		 * join partners.
  		 */
  		if (!isdefault1 && !isdefault2)
  		{
--- 2603,2609 ----
  		 *
  		 * Crude as the above is, it's completely useless if we don't have
  		 * reliable ndistinct values for both sides.  Hence, if either nd1 or
! 		 * nd2 is default, we can't use this.
  		 */
  		if (!isdefault1 && !isdefault2)
  		{
*************** eqjoinsel_semi(Oid operator,
*** 2616,2622 ****
--- 2615,2635 ----
  				uncertainfrac = nd2 / nd1;
  		}
  		else
+ 		{
+ 			/*
+ 			 * In this situation, we basically assume half of the uncertain
+ 			 * rows have join partners.  However, we'd still like to respond
+ 			 * to restriction clauses applied to the inner rel, so what we
+ 			 * really do is assume half of the uncertain rows have partners in
+ 			 * the underlying inner rel, then reduce that fraction by the
+ 			 * previously-determined selectivity of the inner restrictions.
+ 			 */
  			uncertainfrac = 0.5;
+ 			if (vardata2->rel &&
+ 				vardata2->rel->rows > 0 &&
+ 				vardata2->rel->rows < vardata2->rel->tuples)
+ 				uncertainfrac *= vardata2->rel->rows / vardata2->rel->tuples;
+ 		}
  		uncertain = 1.0 - matchfreq1 - nullfrac1;
  		CLAMP_PROBABILITY(uncertain);
  		selec = matchfreq1 + uncertainfrac * uncertain;
*************** eqjoinsel_semi(Oid operator,
*** 2624,2631 ****
  	else
  	{
  		/*
! 		 * Without MCV lists for both sides, we can only use the heuristic
! 		 * about nd1 vs nd2.
  		 */
  		double		nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
  
--- 2637,2644 ----
  	else
  	{
  		/*
! 		 * Without MCV lists for both sides, we can only use the heuristics
! 		 * described above about nd1 vs nd2 and inner restriction clauses.
  		 */
  		double		nullfrac1 = stats1 ? stats1->stanullfrac : 0.0;
  
*************** eqjoinsel_semi(Oid operator,
*** 2637,2643 ****
--- 2650,2662 ----
  				selec = (nd2 / nd1) * (1.0 - nullfrac1);
  		}
  		else
+ 		{
  			selec = 0.5 * (1.0 - nullfrac1);
+ 			if (vardata2->rel &&
+ 				vardata2->rel->rows > 0 &&
+ 				vardata2->rel->rows < vardata2->rel->tuples)
+ 				selec *= vardata2->rel->rows / vardata2->rel->tuples;
+ 		}
  	}
  
  	free_attstatsslot(&sslot1);
