pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix handling of expanded objects in CoerceToDomain and CASE exec
3+ messages / 1 participants
[nested] [flat]

* pgsql: Fix handling of expanded objects in CoerceToDomain and CASE exec
@ 2016-12-22 20:01  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2016-12-22 20:01 UTC (permalink / raw)
  To: pgsql-committers

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

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/c472f2a3353dc4907b54ba90b720310bfb2434eb

Modified Files
--------------
src/backend/executor/execQual.c       | 25 ++++++++++++++++++++-----
src/backend/utils/adt/domains.c       | 10 ++++++++--
src/include/nodes/execnodes.h         |  1 +
src/include/utils/typcache.h          |  2 +-
src/test/regress/expected/case.out    | 26 ++++++++++++++++++++++++++
src/test/regress/expected/plpgsql.out | 20 ++++++++++++++++++++
src/test/regress/sql/case.sql         | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/plpgsql.sql      | 23 +++++++++++++++++++++++
8 files changed, 127 insertions(+), 8 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix handling of expanded objects in CoerceToDomain and CASE exec
@ 2016-12-22 20:01  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2016-12-22 20:01 UTC (permalink / raw)
  To: pgsql-committers

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

Branch
------
REL9_6_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/77cd0dc7e05a91be5deaed7af37eb055c1f080ed

Modified Files
--------------
src/backend/executor/execQual.c       | 25 ++++++++++++++++++++-----
src/backend/utils/adt/domains.c       | 10 ++++++++--
src/include/nodes/execnodes.h         |  1 +
src/include/utils/typcache.h          |  2 +-
src/test/regress/expected/case.out    | 26 ++++++++++++++++++++++++++
src/test/regress/expected/plpgsql.out | 20 ++++++++++++++++++++
src/test/regress/sql/case.sql         | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/plpgsql.sql      | 23 +++++++++++++++++++++++
8 files changed, 127 insertions(+), 8 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix handling of expanded objects in CoerceToDomain and CASE exec
@ 2016-12-22 20:01  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2016-12-22 20:01 UTC (permalink / raw)
  To: pgsql-committers

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

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/cd1b215692d2cadf499936dba05f1f60bce59344

Modified Files
--------------
src/backend/executor/execQual.c       | 25 ++++++++++++++++++++-----
src/backend/utils/adt/domains.c       | 10 ++++++++--
src/include/nodes/execnodes.h         |  1 +
src/include/utils/typcache.h          |  2 +-
src/test/regress/expected/case.out    | 26 ++++++++++++++++++++++++++
src/test/regress/expected/plpgsql.out | 20 ++++++++++++++++++++
src/test/regress/sql/case.sql         | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/plpgsql.sql      | 23 +++++++++++++++++++++++
8 files changed, 127 insertions(+), 8 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2016-12-22 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-12-22 20:01 pgsql: Fix handling of expanded objects in CoerceToDomain and CASE exec Tom Lane <tgl@sss.pgh.pa.us>
2016-12-22 20:01 pgsql: Fix handling of expanded objects in CoerceToDomain and CASE exec Tom Lane <tgl@sss.pgh.pa.us>
2016-12-22 20:01 pgsql: Fix handling of expanded objects in CoerceToDomain and CASE exec Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox