From 6da378dbc97f1b96bf5778a558e168a0dc405bce Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 22 Feb 2013 09:21:50 -0500 Subject: Fix whole-row references in postgres_fdw. The optimization to not retrieve unnecessary columns wasn't smart enough. Noted by Thom Brown. --- contrib/postgres_fdw/deparse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'contrib/postgres_fdw/deparse.c') diff --git a/contrib/postgres_fdw/deparse.c b/contrib/postgres_fdw/deparse.c index 93f2541cfc1..0293115054f 100644 --- a/contrib/postgres_fdw/deparse.c +++ b/contrib/postgres_fdw/deparse.c @@ -364,6 +364,7 @@ deparseSimpleSql(StringInfo buf, { RangeTblEntry *rte = root->simple_rte_array[baserel->relid]; Bitmapset *attrs_used = NULL; + bool have_wholerow; bool first; AttrNumber attr; ListCell *lc; @@ -381,6 +382,10 @@ deparseSimpleSql(StringInfo buf, &attrs_used); } + /* If there's a whole-row reference, we'll need all the columns. */ + have_wholerow = bms_is_member(0 - FirstLowInvalidHeapAttributeNumber, + attrs_used); + /* * Construct SELECT list * @@ -401,7 +406,8 @@ deparseSimpleSql(StringInfo buf, appendStringInfo(buf, ", "); first = false; - if (bms_is_member(attr - FirstLowInvalidHeapAttributeNumber, + if (have_wholerow || + bms_is_member(attr - FirstLowInvalidHeapAttributeNumber, attrs_used)) deparseColumnRef(buf, baserel->relid, attr, root); else -- cgit v1.2.3