From 449d5acd7d02fae0086ecfbbd45a13f28a40e795 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon, 11 Nov 2013 16:36:27 -0500
Subject: [PATCH] Fix failure with whole-row reference to a subquery.

Simple oversight in commit 1cb108efb0e60d87e4adec38e7636b6e8efbeb57 ---
recursively examining a subquery output column is only sane if the
original Var refers to a single output column.  Found by Kevin Grittner.
---
 src/backend/utils/adt/selfuncs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index a5a9fa69ab6..84c27a95a91 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -4502,6 +4502,12 @@ examine_simple_variable(PlannerInfo *root, Var *var,
 		RelOptInfo *rel;
 		TargetEntry *ste;
 
+		/*
+		 * Punt if it's a whole-row var rather than a plain column reference.
+		 */
+		if (var->varattno == InvalidAttrNumber)
+			return;
+
 		/*
 		 * Punt if subquery uses set operations or GROUP BY, as these will
 		 * mash underlying columns' stats beyond recognition.  (Set ops are
-- 
GitLab