postgresql/src/backend
Andres Freund ad22783792 Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relation.
Four related issues:

1) attnos/varnos/resnos for EXCLUDED were out of sync when a column
   after one dropped in the underlying relation was referenced.
2) References to whole-row variables (i.e. EXCLUDED.*) lead to errors.
3) It was possible to reference system columns in the EXCLUDED pseudo
   relations, even though they would not have valid contents.
4) References to EXCLUDED were rewritten by the RLS machinery, as
   EXCLUDED was treated as if it were the underlying relation.

To fix the first two issues, generate the excluded targetlist with
dropped columns in mind and add an entry for whole row
variables. Instead of unconditionally adding a wholerow entry we could
pull up the expression if needed, but doing it unconditionally seems
simpler. The wholerow entry is only really needed for ruleutils/EXPLAIN
support anyway.

The remaining two issues are addressed by changing the EXCLUDED RTE to
have relkind = composite. That fits with EXCLUDED not actually being a
real relation, and allows to treat it differently in the relevant
places. scanRTEForColumn now skips looking up system columns when the
RTE has a composite relkind; fireRIRrules() already had a corresponding
check, thereby preventing RLS expansion on EXCLUDED.

Also add tests for these issues, and improve a few comments around
excluded handling in setrefs.c.

Reported-By: Peter Geoghegan, Geoff Winkless
Author: Andres Freund, Amit Langote, Peter Geoghegan
Discussion: CAEzk6fdzJ3xYQZGbcuYM2rBd2BuDkUksmK=mY9UYYDugg_GgZg@mail.gmail.com,
   CAM3SWZS+CauzbiCEcg-GdE6K6ycHE_Bz6Ksszy8AoixcMHOmsA@mail.gmail.com
Backpatch: 9.5, where ON CONFLICT was introduced
2015-10-03 15:12:10 +02:00
..
access Don't disable commit_ts in standby if enabled locally 2015-10-02 12:49:01 -03:00
bootstrap pgindent run for 9.5 2015-05-23 21:35:49 -04:00
catalog Determine whether it's safe to attempt a parallel plan for a query. 2015-09-16 15:38:47 -04:00
commands Fix errors in commit a04bb65f70. 2015-09-30 23:37:26 -04:00
executor Add a Gather executor node. 2015-09-30 19:23:36 -04:00
foreign Code review for foreign/custom join pushdown patch. 2015-05-10 14:36:36 -04:00
lib Avoid use of float arithmetic in bipartite_match.c. 2015-08-23 13:02:18 -04:00
libpq Support RADIUS passwords up to 128 characters 2015-09-06 14:31:53 +02:00
main Revoke support for strxfrm() that write past the specified array length. 2015-07-08 20:44:21 -04:00
nodes Fix readfuncs/outfuncs problems in last night's Gather patch. 2015-10-01 09:19:26 -04:00
optimizer Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relation. 2015-10-03 15:12:10 +02:00
parser Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relation. 2015-10-03 15:12:10 +02:00
po Translation updates 2015-06-28 23:56:55 -04:00
port Rely on inline functions even if that causes warnings in older compilers. 2015-08-05 18:19:52 +02:00
postmaster Remove files signaling a standby promotion request at postmaster startup 2015-09-09 22:51:44 +09:00
regex Add recursion depth protections to regular expression matching. 2015-10-02 14:51:58 -04:00
replication Fix "sesssion" typo 2015-09-28 19:13:42 -03:00
rewrite Include policies based on ACLs needed 2015-09-30 07:39:24 -04:00
snowball Remove no-longer-required function declarations. 2015-05-24 12:20:23 -04:00
storage Use LOCKBIT_ON() instead of a bit shift in a few places. 2015-09-28 10:57:15 -04:00
tcop Add recursion depth protections to regular expression matching. 2015-10-02 14:51:58 -04:00
tsearch pgindent run for 9.5 2015-05-23 21:35:49 -04:00
utils Add recursion depth protection to LIKE matching. 2015-10-02 15:00:51 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Fix build problems in commit aa65de042f. 2015-09-11 14:56:17 -04:00
nls.mk Remove trailing slashes from directories in find command 2015-09-18 22:06:54 -04:00