pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Mark read/write expanded values as read-only in ExecProject().
5+ messages / 2 participants
[nested] [flat]
* pgsql: Mark read/write expanded values as read-only in ExecProject().
@ 2016-06-03 19:15 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2016-06-03 19:15 UTC (permalink / raw)
To: pgsql-committers
Mark read/write expanded values as read-only in ExecProject().
If a plan node output expression returns an "expanded" datum, and that
output column is referenced in more than one place in upper-level plan
nodes, we need to ensure that what is returned is a read-only reference
not a read/write reference. Otherwise one of the referencing sites could
scribble on or even delete the expanded datum before we have evaluated the
others. Commit 1dc5ebc9077ab742, which introduced this feature, supposed
that it'd be sufficient to make SubqueryScan nodes force their output
columns to read-only state. The folly of that was revealed by bug #14174
from Andrew Gierth, and really should have been immediately obvious
considering that the planner will happily optimize SubqueryScan nodes
out of the plan without any regard for this issue.
The safest fix seems to be to make ExecProject() force its results into
read-only state; that will cover every case where a plan node returns
expression results. Actually we can delegate this to ExecTargetList()
since we can recursively assume that plain Vars will not reference
read-write datums. That should keep the extra overhead down to something
minimal. We no longer need ExecMakeSlotContentsReadOnly(), which was
introduced only in support of the idea that just a few plan node types
would need to do this.
In the future it would be nice to have the planner account for this problem
and inject force-to-read-only expression evaluation nodes into only the
places where there's a risk of multiple evaluation. That's not a suitable
solution for 9.5 or even 9.6 at this point, though.
Report: <20160603124628.9932.41279@wrigleys.postgresql.org>
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/69f526aa4947135f2570c4ec545f6387d4b14585
Modified Files
--------------
src/backend/executor/execQual.c | 19 +++++++++++++
src/backend/executor/execTuples.c | 47 ---------------------------------
src/backend/executor/nodeSubqueryscan.c | 8 ------
src/include/executor/tuptable.h | 1 -
src/test/regress/expected/plpgsql.out | 40 +++++++++++++++++++++++++++-
src/test/regress/sql/plpgsql.sql | 32 +++++++++++++++++++++-
6 files changed, 89 insertions(+), 58 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] 5+ messages in thread
* pgsql: Mark read/write expanded values as read-only in ExecProject().
@ 2016-06-03 19:15 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2016-06-03 19:15 UTC (permalink / raw)
To: pgsql-committers
Mark read/write expanded values as read-only in ExecProject().
If a plan node output expression returns an "expanded" datum, and that
output column is referenced in more than one place in upper-level plan
nodes, we need to ensure that what is returned is a read-only reference
not a read/write reference. Otherwise one of the referencing sites could
scribble on or even delete the expanded datum before we have evaluated the
others. Commit 1dc5ebc9077ab742, which introduced this feature, supposed
that it'd be sufficient to make SubqueryScan nodes force their output
columns to read-only state. The folly of that was revealed by bug #14174
from Andrew Gierth, and really should have been immediately obvious
considering that the planner will happily optimize SubqueryScan nodes
out of the plan without any regard for this issue.
The safest fix seems to be to make ExecProject() force its results into
read-only state; that will cover every case where a plan node returns
expression results. Actually we can delegate this to ExecTargetList()
since we can recursively assume that plain Vars will not reference
read-write datums. That should keep the extra overhead down to something
minimal. We no longer need ExecMakeSlotContentsReadOnly(), which was
introduced only in support of the idea that just a few plan node types
would need to do this.
In the future it would be nice to have the planner account for this problem
and inject force-to-read-only expression evaluation nodes into only the
places where there's a risk of multiple evaluation. That's not a suitable
solution for 9.5 or even 9.6 at this point, though.
Report: <20160603124628.9932.41279@wrigleys.postgresql.org>
Branch
------
REL9_5_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/a102f98e26bc7d21eb5246fd345f8e3ab31be109
Modified Files
--------------
src/backend/executor/execQual.c | 19 +++++++++++++
src/backend/executor/execTuples.c | 47 ---------------------------------
src/backend/executor/nodeSubqueryscan.c | 8 ------
src/include/executor/tuptable.h | 1 -
src/test/regress/expected/plpgsql.out | 40 +++++++++++++++++++++++++++-
src/test/regress/sql/plpgsql.sql | 32 +++++++++++++++++++++-
6 files changed, 89 insertions(+), 58 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] 5+ messages in thread
* pgsql: Mark read/write expanded values as read-only in ValuesNext(), to
@ 2016-06-03 22:07 Tom Lane <tgl@sss.pgh.pa.us>
2016-08-24 23:41 ` Re: pgsql: Mark read/write expanded values as read-only in ValuesNext(), to Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2016-06-03 22:07 UTC (permalink / raw)
To: pgsql-committers
Mark read/write expanded values as read-only in ValuesNext(), too.
Further thought about bug #14174 motivated me to try the case of a
R/W datum being returned from a VALUES list, and sure enough it was
broken. Fix that.
Also add a regression test case exercising the same scenario for
FunctionScan. That's not broken right now, because the function's
result will get shoved into a tuplestore between generation and use;
but it could easily become broken whenever we get around to optimizing
FunctionScan better.
There don't seem to be any other places where we put the result of
expression evaluation into a virtual tuple slot that could then be
the source for Vars of further expression evaluation, so I think
this is the end of this bug.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/9eaf5be5067571febf323337fc58bcac97b9f5d5
Modified Files
--------------
src/backend/executor/nodeValuesscan.c | 14 ++++++++++++++
src/test/regress/expected/plpgsql.out | 32 ++++++++++++++++++++++++++++++++
src/test/regress/sql/plpgsql.sql | 12 ++++++++++++
3 files changed, 58 insertions(+)
--
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] 5+ messages in thread
* Re: pgsql: Mark read/write expanded values as read-only in ValuesNext(), to
2016-06-03 22:07 pgsql: Mark read/write expanded values as read-only in ValuesNext(), to Tom Lane <tgl@sss.pgh.pa.us>
@ 2016-08-24 23:41 ` Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 5+ messages in thread
From: Andres Freund @ 2016-08-24 23:41 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers
On 2016-06-03 22:07:21 +0000, Tom Lane wrote:
> Also add a regression test case exercising the same scenario for
> FunctionScan. That's not broken right now, because the function's
> result will get shoved into a tuplestore between generation and use;
> but it could easily become broken whenever we get around to optimizing
> FunctionScan better.
Indeed, I just locally broke that for a few minutes. Thanks for that.
--
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] 5+ messages in thread
* pgsql: Mark read/write expanded values as read-only in ValuesNext(), to
@ 2016-06-03 22:07 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2016-06-03 22:07 UTC (permalink / raw)
To: pgsql-committers
Mark read/write expanded values as read-only in ValuesNext(), too.
Further thought about bug #14174 motivated me to try the case of a
R/W datum being returned from a VALUES list, and sure enough it was
broken. Fix that.
Also add a regression test case exercising the same scenario for
FunctionScan. That's not broken right now, because the function's
result will get shoved into a tuplestore between generation and use;
but it could easily become broken whenever we get around to optimizing
FunctionScan better.
There don't seem to be any other places where we put the result of
expression evaluation into a virtual tuple slot that could then be
the source for Vars of further expression evaluation, so I think
this is the end of this bug.
Branch
------
REL9_5_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/8355897ff296a3634f6b9c3da444622a02adda9c
Modified Files
--------------
src/backend/executor/nodeValuesscan.c | 14 ++++++++++++++
src/test/regress/expected/plpgsql.out | 32 ++++++++++++++++++++++++++++++++
src/test/regress/sql/plpgsql.sql | 12 ++++++++++++
3 files changed, 58 insertions(+)
--
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] 5+ messages in thread
end of thread, other threads:[~2016-08-24 23:41 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 19:15 pgsql: Mark read/write expanded values as read-only in ExecProject(). Tom Lane <tgl@sss.pgh.pa.us>
2016-06-03 19:15 pgsql: Mark read/write expanded values as read-only in ExecProject(). Tom Lane <tgl@sss.pgh.pa.us>
2016-06-03 22:07 pgsql: Mark read/write expanded values as read-only in ValuesNext(), to Tom Lane <tgl@sss.pgh.pa.us>
2016-08-24 23:41 ` Re: pgsql: Mark read/write expanded values as read-only in ValuesNext(), to Andres Freund <andres@anarazel.de>
2016-06-03 22:07 pgsql: Mark read/write expanded values as read-only in ValuesNext(), to 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