mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
postgres_fdw: Avoid possible misbehavior when RETURNING tableoid column only.
deparseReturningList ended up adding up RETURNING NULL to the code, but code elsewhere saw an empty list of attributes and concluded that it should not expect tuples from the remote side. Etsuro Fujita and Robert Haas, reviewed by Thom Brown
This commit is contained in:
@ -110,6 +110,7 @@ static void deparseTargetList(StringInfo buf,
|
||||
PlannerInfo *root,
|
||||
Index rtindex,
|
||||
Relation rel,
|
||||
bool is_returning,
|
||||
Bitmapset *attrs_used,
|
||||
List **retrieved_attrs);
|
||||
static void deparseReturningList(StringInfo buf, PlannerInfo *root,
|
||||
@ -721,7 +722,7 @@ deparseSelectSql(StringInfo buf,
|
||||
* Construct SELECT list
|
||||
*/
|
||||
appendStringInfoString(buf, "SELECT ");
|
||||
deparseTargetList(buf, root, baserel->relid, rel, attrs_used,
|
||||
deparseTargetList(buf, root, baserel->relid, rel, false, attrs_used,
|
||||
retrieved_attrs);
|
||||
|
||||
/*
|
||||
@ -735,7 +736,8 @@ deparseSelectSql(StringInfo buf,
|
||||
|
||||
/*
|
||||
* Emit a target list that retrieves the columns specified in attrs_used.
|
||||
* This is used for both SELECT and RETURNING targetlists.
|
||||
* This is used for both SELECT and RETURNING targetlists; the is_returning
|
||||
* parameter is true only for a RETURNING targetlist.
|
||||
*
|
||||
* The tlist text is appended to buf, and we also create an integer List
|
||||
* of the columns being retrieved, which is returned to *retrieved_attrs.
|
||||
@ -745,6 +747,7 @@ deparseTargetList(StringInfo buf,
|
||||
PlannerInfo *root,
|
||||
Index rtindex,
|
||||
Relation rel,
|
||||
bool is_returning,
|
||||
Bitmapset *attrs_used,
|
||||
List **retrieved_attrs)
|
||||
{
|
||||
@ -774,6 +777,8 @@ deparseTargetList(StringInfo buf,
|
||||
{
|
||||
if (!first)
|
||||
appendStringInfoString(buf, ", ");
|
||||
else if (is_returning)
|
||||
appendStringInfoString(buf, " RETURNING ");
|
||||
first = false;
|
||||
|
||||
deparseColumnRef(buf, rtindex, i, root);
|
||||
@ -791,6 +796,8 @@ deparseTargetList(StringInfo buf,
|
||||
{
|
||||
if (!first)
|
||||
appendStringInfoString(buf, ", ");
|
||||
else if (is_returning)
|
||||
appendStringInfoString(buf, " RETURNING ");
|
||||
first = false;
|
||||
|
||||
appendStringInfoString(buf, "ctid");
|
||||
@ -800,7 +807,7 @@ deparseTargetList(StringInfo buf,
|
||||
}
|
||||
|
||||
/* Don't generate bad syntax if no undropped columns */
|
||||
if (first)
|
||||
if (first && !is_returning)
|
||||
appendStringInfoString(buf, "NULL");
|
||||
}
|
||||
|
||||
@ -1016,11 +1023,8 @@ deparseReturningList(StringInfo buf, PlannerInfo *root,
|
||||
}
|
||||
|
||||
if (attrs_used != NULL)
|
||||
{
|
||||
appendStringInfoString(buf, " RETURNING ");
|
||||
deparseTargetList(buf, root, rtindex, rel, attrs_used,
|
||||
deparseTargetList(buf, root, rtindex, rel, true, attrs_used,
|
||||
retrieved_attrs);
|
||||
}
|
||||
else
|
||||
*retrieved_attrs = NIL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user