postgresql/src/include
Tom Lane 06ba530968 Fix creation of resjunk tlist entries for inherited mixed UPDATE/DELETE.
rewriteTargetListUD's processing is dependent on the relkind of the query's
target table.  That was fine at the time it was made to act that way, even
for queries on inheritance trees, because all tables in an inheritance tree
would necessarily be plain tables.  However, the 9.5 feature addition
allowing some members of an inheritance tree to be foreign tables broke the
assumption that rewriteTargetListUD's output tlist could be applied to all
child tables with nothing more than column-number mapping.  This led to
visible failures if foreign child tables had row-level triggers, and would
also break in cases where child tables belonged to FDWs that used methods
other than CTID for row identification.

To fix, delay running rewriteTargetListUD until after the planner has
expanded inheritance, so that it is applied separately to the (already
mapped) tlist for each child table.  We can conveniently call it from
preprocess_targetlist.  Refactor associated code slightly to avoid the
need to heap_open the target relation multiple times during
preprocess_targetlist.  (The APIs remain a bit ugly, particularly around
the point of which steps scribble on parse->targetList and which don't.
But avoiding such scribbling would require a change in FDW callback APIs,
which is more pain than it's worth.)

Also fix ExecModifyTable to ensure that "tupleid" is reset to NULL when
we transition from rows providing a CTID to rows that don't.  (That's
really an independent bug, but it manifests in much the same cases.)

Add a regression test checking one manifestation of this problem, which
was that row-level triggers on a foreign child table did not work right.

Back-patch to 9.5 where the problem was introduced.

Etsuro Fujita, reviewed by Ildus Kurbangaliev and Ashutosh Bapat

Discussion: https://postgr.es/m/20170514150525.0346ba72@postgrespro.ru
2017-11-27 17:54:10 -05:00
..
access Pad XLogReaderState's main_data buffer more aggressively. 2017-11-26 15:17:25 -05:00
bootstrap Update copyright for 2016 2016-01-02 13:33:40 -05:00
catalog Always require SELECT permission for ON CONFLICT DO UPDATE. 2017-11-06 09:16:24 +00:00
commands Final pgindent + perltidy run for 9.6. 2016-08-15 13:42:51 -04:00
common Fix integer-overflow problems in interval comparison. 2017-04-05 23:51:28 -04:00
datatype Be more careful about out-of-range dates and timestamps. 2016-03-16 19:09:28 -04:00
executor Fix crash when logical decoding is invoked from a PL function. 2017-10-06 19:18:58 -04:00
fe_utils Fix assorted places in psql to print version numbers >= 10 in new style. 2016-08-16 15:58:46 -04:00
foreign Remove GetUserMappingId() and GetUserMappingById(). 2016-07-22 11:32:23 -04:00
lib Revert "Permit dump/reload of not-too-large >1GB tuples" 2016-12-06 12:46:03 -03:00
libpq Give nicer error message when connecting to a v10 server requiring SCRAM. 2017-05-05 11:24:02 +03:00
mb Update copyright for 2016 2016-01-02 13:33:40 -05:00
nodes Fix mistaken failure to allow parallelism in corner case. 2017-10-27 16:12:16 +02:00
optimizer Fix creation of resjunk tlist entries for inherited mixed UPDATE/DELETE. 2017-11-27 17:54:10 -05:00
parser Fix type-safety problem with parallel aggregate serial/deserialization. 2016-06-22 16:52:41 -04:00
port Fix unportable definition of BSWAP64() macro. 2017-02-24 15:21:39 -05:00
portability Update copyright for 2016 2016-01-02 13:33:40 -05:00
postmaster Avoid using PostmasterRandom() for DSM control segment ID. 2016-09-23 09:54:11 -04:00
regex Suppress compiler warnings about useless comparison of unsigned to zero. 2016-02-15 17:12:16 -05:00
replication Fix leaking of small spilled subtransactions during logical decoding. 2017-06-18 19:13:15 -07:00
rewrite Fix creation of resjunk tlist entries for inherited mixed UPDATE/DELETE. 2017-11-27 17:54:10 -05:00
snowball Update copyright for 2016 2016-01-02 13:33:40 -05:00
storage Add support for Motorola 88K to s_lock.h. 2017-11-20 17:57:46 -05:00
tcop Remove dead code and fix comments in fast-path function handling. 2017-04-06 09:11:11 +03:00
tsearch Fix typos in comments. 2017-02-06 11:34:15 +02:00
utils Fix problems with the "role" GUC and parallel query. 2017-10-29 13:14:37 +05:30
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Prevent int128 from requiring more than MAXALIGN alignment. 2017-11-14 17:49:49 -05:00
fmgr.h Revert addition of PGDLLEXPORT in PG_FUNCTION_INFO_V1 macro. 2016-10-12 18:01:52 -04:00
funcapi.h Add a utility function to extract variadic function arguments 2017-10-25 07:19:59 -04:00
getaddrinfo.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
getopt_long.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
Makefile Create src/fe_utils/, and move stuff into there from pg_dump's dumputils. 2016-03-24 15:55:57 -04:00
miscadmin.h Unify SIGHUP handling between normal and walsender backends. 2017-06-05 19:18:16 -07:00
pg_config.h.in Prevent int128 from requiring more than MAXALIGN alignment. 2017-11-14 17:49:49 -05:00
pg_config.h.win32 Prevent int128 from requiring more than MAXALIGN alignment. 2017-11-14 17:49:49 -05:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Bring some clarity to the defaults for the xxx_flush_after parameters. 2016-11-25 18:36:10 -05:00
pg_getopt.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_trace.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pgstat.h Fix typos in comments. 2016-10-26 11:13:17 +03:00
pgtar.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pgtime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
port.h Run the postmaster's signal handlers without SA_RESTART. 2017-04-24 13:00:23 -04:00
postgres.h Adjust DatumGetBool macro, this time for sure. 2016-04-28 11:50:58 -04:00
postgres_ext.h Add a nonlocalized version of the severity field to client error messages. 2016-08-26 16:20:24 -04:00
postgres_fe.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rusagestub.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
windowapi.h Update copyright for 2016 2016-01-02 13:33:40 -05:00