diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 56943f2..43e6220 100644
*** a/src/backend/utils/adt/selfuncs.c
--- b/src/backend/utils/adt/selfuncs.c
*************** get_variable_numdistinct(VariableStatDat
*** 4768,4773 ****
--- 4768,4784 ----
  		 */
  		stadistinct = 2.0;
  	}
+ 	else if (vardata->rel && vardata->rel->rtekind == RTE_VALUES)
+ 	{
+ 		/*
+ 		 * If the Var represents a column of a VALUES RTE, assume it's unique.
+ 		 * This could of course be very wrong, but it should tend to be true
+ 		 * in well-written queries.  We could consider examining the RTE
+ 		 * contents to get some real statistics; but that only works if the
+ 		 * expressions are constants, and it would be pretty expensive anyway.
+ 		 */
+ 		stadistinct = -1.0;		/* unique (and all non null) */
+ 	}
  	else
  	{
  		/*
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index fcfb0d4..25715c9 100644
*** a/src/include/nodes/relation.h
--- b/src/include/nodes/relation.h
*************** typedef struct PlannerInfo
*** 399,405 ****
   *
   *		relid - RTE index (this is redundant with the relids field, but
   *				is provided for convenience of access)
!  *		rtekind - distinguishes plain relation, subquery, or function RTE
   *		min_attr, max_attr - range of valid AttrNumbers for rel
   *		attr_needed - array of bitmapsets indicating the highest joinrel
   *				in which each attribute is needed; if bit 0 is set then
--- 399,405 ----
   *
   *		relid - RTE index (this is redundant with the relids field, but
   *				is provided for convenience of access)
!  *		rtekind - copy of RTE's rtekind field
   *		min_attr, max_attr - range of valid AttrNumbers for rel
   *		attr_needed - array of bitmapsets indicating the highest joinrel
   *				in which each attribute is needed; if bit 0 is set then
*************** typedef struct RelOptInfo
*** 512,518 ****
  	/* information about a base rel (not set for join rels!) */
  	Index		relid;
  	Oid			reltablespace;	/* containing tablespace */
! 	RTEKind		rtekind;		/* RELATION, SUBQUERY, or FUNCTION */
  	AttrNumber	min_attr;		/* smallest attrno of rel (often <0) */
  	AttrNumber	max_attr;		/* largest attrno of rel */
  	Relids	   *attr_needed;	/* array indexed [min_attr .. max_attr] */
--- 512,518 ----
  	/* information about a base rel (not set for join rels!) */
  	Index		relid;
  	Oid			reltablespace;	/* containing tablespace */
! 	RTEKind		rtekind;		/* RELATION, SUBQUERY, FUNCTION, etc */
  	AttrNumber	min_attr;		/* smallest attrno of rel (often <0) */
  	AttrNumber	max_attr;		/* largest attrno of rel */
  	Relids	   *attr_needed;	/* array indexed [min_attr .. max_attr] */
