postgresql/src/include/nodes
Tom Lane c472f2a335 Fix handling of expanded objects in CoerceToDomain and CASE execution.
When the input value to a CoerceToDomain expression node is a read-write
expanded datum, we should pass a read-only pointer to any domain CHECK
expressions and then return the original read-write pointer as the
expression result.  Previously we were blindly passing the same pointer to
all the consumers of the value, making it possible for a function in CHECK
to modify or even delete the expanded value.  (Since a plpgsql function
will absorb a passed-in read-write expanded array as a local variable
value, it will in fact delete the value on exit.)

A similar hazard of passing the same read-write pointer to multiple
consumers exists in domain_check() and in ExecEvalCase, so fix those too.

The fix requires adding MakeExpandedObjectReadOnly calls at the appropriate
places, which is simple enough except that we need to get the data type's
typlen from somewhere.  For the domain cases, solve this by redefining
DomainConstraintRef.tcache as okay for callers to access; there wasn't any
reason for the original convention against that, other than not wanting the
API of typcache.c to be any wider than it had to be.  For CASE, there's
no good solution except to add a syscache lookup during executor start.

Per bug #14472 from Marcos Castedo.  Back-patch to 9.5 where expanded
values were introduced.

Discussion: https://postgr.es/m/15225.1482431619@sss.pgh.pa.us
2016-12-22 15:01:39 -05:00
..
bitmapset.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
execnodes.h Fix handling of expanded objects in CoerceToDomain and CASE execution. 2016-12-22 15:01:39 -05:00
lockoptions.h Improve representation of PlanRowMark. 2015-03-15 18:41:47 -04:00
makefuncs.h Fix CREATE MATVIEW/CREATE TABLE AS ... WITH NO DATA to not plan the query. 2016-06-27 15:57:21 -04:00
memnodes.h Move memory context callback declarations into palloc.h. 2015-03-01 12:31:32 -05:00
nodeFuncs.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
nodes.h Get rid of the planner's LateralJoinInfo data structure. 2015-12-11 15:52:39 -05:00
params.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
parsenodes.h Do not write out WCOs in Query 2015-10-05 07:38:56 -04:00
pg_list.h Support GROUPING SETS, CUBE and ROLLUP. 2015-05-16 03:46:31 +02:00
plannodes.h Fix improper repetition of previous results from a hashed aggregate. 2016-08-24 14:37:50 -04:00
primnodes.h Fix assorted fallout from IS [NOT] NULL patch. 2016-07-28 16:09:15 -04:00
print.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
readfuncs.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
relation.h Get rid of the planner's LateralJoinInfo data structure. 2015-12-11 15:52:39 -05:00
replnodes.h Update copyright for 2015 2015-01-06 11:43:47 -05:00
tidbitmap.h Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
value.h Update copyright for 2015 2015-01-06 11:43:47 -05:00