pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix incorrect matching of subexpressions in outer-join plan node
11+ messages / 3 participants
[nested] [flat]
* pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-04 23:55 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Tom Lane @ 2015-04-04 23:55 UTC (permalink / raw)
To: pgsql-committers
Fix incorrect matching of subexpressions in outer-join plan nodes.
Previously we would re-use input subexpressions in all expression trees
attached to a Join plan node. However, if it's an outer join and the
subexpression appears in the nullable-side input, this is potentially
incorrect for apparently-matching subexpressions that came from above
the outer join (ie, targetlist and qpqual expressions), because the
executor will treat the subexpression value as NULL when maybe it should
not be.
The case is fairly hard to hit because (a) you need a non-strict
subexpression (else NULL is correct), and (b) we don't usually compute
expressions in the outputs of non-toplevel plan nodes. But we might do
so if the expressions are sort keys for a mergejoin, for example.
Probably in the long run we should make a more explicit distinction between
Vars appearing above and below an outer join, but that will be a major
planner redesign and not at all back-patchable. For the moment, just hack
set_join_references so that it will not match any non-Var expressions
coming from nullable inputs to expressions that came from above the join.
(This is somewhat overkill, in that a strict expression could still be
matched, but it doesn't seem worth the effort to check that.)
Per report from Qingqing Zhou. The added regression test case is based
on his example.
This has been broken for a very long time, so back-patch to all active
branches.
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/ca6805338fba010cc3f8b842905d7a62e280b7ab
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 67 +++++++++++++++++++++++++++-------
src/test/regress/expected/join.out | 48 ++++++++++++++++++++++++
src/test/regress/sql/join.sql | 20 ++++++++++
3 files changed, 121 insertions(+), 14 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] 11+ messages in thread
* pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-04 23:55 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Tom Lane @ 2015-04-04 23:55 UTC (permalink / raw)
To: pgsql-committers
Fix incorrect matching of subexpressions in outer-join plan nodes.
Previously we would re-use input subexpressions in all expression trees
attached to a Join plan node. However, if it's an outer join and the
subexpression appears in the nullable-side input, this is potentially
incorrect for apparently-matching subexpressions that came from above
the outer join (ie, targetlist and qpqual expressions), because the
executor will treat the subexpression value as NULL when maybe it should
not be.
The case is fairly hard to hit because (a) you need a non-strict
subexpression (else NULL is correct), and (b) we don't usually compute
expressions in the outputs of non-toplevel plan nodes. But we might do
so if the expressions are sort keys for a mergejoin, for example.
Probably in the long run we should make a more explicit distinction between
Vars appearing above and below an outer join, but that will be a major
planner redesign and not at all back-patchable. For the moment, just hack
set_join_references so that it will not match any non-Var expressions
coming from nullable inputs to expressions that came from above the join.
(This is somewhat overkill, in that a strict expression could still be
matched, but it doesn't seem worth the effort to check that.)
Per report from Qingqing Zhou. The added regression test case is based
on his example.
This has been broken for a very long time, so back-patch to all active
branches.
Branch
------
REL9_2_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/b7d493bf78328fbb450e9db56a60e536a6fb6bbf
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 67 +++++++++++++++++++++++++++-------
src/test/regress/expected/join.out | 48 ++++++++++++++++++++++++
src/test/regress/sql/join.sql | 20 ++++++++++
3 files changed, 121 insertions(+), 14 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] 11+ messages in thread
* pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-04 23:55 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Tom Lane @ 2015-04-04 23:55 UTC (permalink / raw)
To: pgsql-committers
Fix incorrect matching of subexpressions in outer-join plan nodes.
Previously we would re-use input subexpressions in all expression trees
attached to a Join plan node. However, if it's an outer join and the
subexpression appears in the nullable-side input, this is potentially
incorrect for apparently-matching subexpressions that came from above
the outer join (ie, targetlist and qpqual expressions), because the
executor will treat the subexpression value as NULL when maybe it should
not be.
The case is fairly hard to hit because (a) you need a non-strict
subexpression (else NULL is correct), and (b) we don't usually compute
expressions in the outputs of non-toplevel plan nodes. But we might do
so if the expressions are sort keys for a mergejoin, for example.
Probably in the long run we should make a more explicit distinction between
Vars appearing above and below an outer join, but that will be a major
planner redesign and not at all back-patchable. For the moment, just hack
set_join_references so that it will not match any non-Var expressions
coming from nullable inputs to expressions that came from above the join.
(This is somewhat overkill, in that a strict expression could still be
matched, but it doesn't seem worth the effort to check that.)
Per report from Qingqing Zhou. The added regression test case is based
on his example.
This has been broken for a very long time, so back-patch to all active
branches.
Branch
------
REL9_3_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/e105df208cf4a5d707a7ad0b9e6a4a23964c534b
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 67 +++++++++++++++++++++++++++-------
src/test/regress/expected/join.out | 48 ++++++++++++++++++++++++
src/test/regress/sql/join.sql | 20 ++++++++++
3 files changed, 121 insertions(+), 14 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] 11+ messages in thread
* pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-04 23:55 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Tom Lane @ 2015-04-04 23:55 UTC (permalink / raw)
To: pgsql-committers
Fix incorrect matching of subexpressions in outer-join plan nodes.
Previously we would re-use input subexpressions in all expression trees
attached to a Join plan node. However, if it's an outer join and the
subexpression appears in the nullable-side input, this is potentially
incorrect for apparently-matching subexpressions that came from above
the outer join (ie, targetlist and qpqual expressions), because the
executor will treat the subexpression value as NULL when maybe it should
not be.
The case is fairly hard to hit because (a) you need a non-strict
subexpression (else NULL is correct), and (b) we don't usually compute
expressions in the outputs of non-toplevel plan nodes. But we might do
so if the expressions are sort keys for a mergejoin, for example.
Probably in the long run we should make a more explicit distinction between
Vars appearing above and below an outer join, but that will be a major
planner redesign and not at all back-patchable. For the moment, just hack
set_join_references so that it will not match any non-Var expressions
coming from nullable inputs to expressions that came from above the join.
(This is somewhat overkill, in that a strict expression could still be
matched, but it doesn't seem worth the effort to check that.)
Per report from Qingqing Zhou. The added regression test case is based
on his example.
This has been broken for a very long time, so back-patch to all active
branches.
Branch
------
REL9_4_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/1d71d36ffeae15616672b5c34e4f0d6f3484fa45
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 67 +++++++++++++++++++++++++++-------
src/test/regress/expected/join.out | 48 ++++++++++++++++++++++++
src/test/regress/sql/join.sql | 20 ++++++++++
3 files changed, 121 insertions(+), 14 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] 11+ messages in thread
* pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-04 23:55 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Tom Lane @ 2015-04-04 23:55 UTC (permalink / raw)
To: pgsql-committers
Fix incorrect matching of subexpressions in outer-join plan nodes.
Previously we would re-use input subexpressions in all expression trees
attached to a Join plan node. However, if it's an outer join and the
subexpression appears in the nullable-side input, this is potentially
incorrect for apparently-matching subexpressions that came from above
the outer join (ie, targetlist and qpqual expressions), because the
executor will treat the subexpression value as NULL when maybe it should
not be.
The case is fairly hard to hit because (a) you need a non-strict
subexpression (else NULL is correct), and (b) we don't usually compute
expressions in the outputs of non-toplevel plan nodes. But we might do
so if the expressions are sort keys for a mergejoin, for example.
Probably in the long run we should make a more explicit distinction between
Vars appearing above and below an outer join, but that will be a major
planner redesign and not at all back-patchable. For the moment, just hack
set_join_references so that it will not match any non-Var expressions
coming from nullable inputs to expressions that came from above the join.
(This is somewhat overkill, in that a strict expression could still be
matched, but it doesn't seem worth the effort to check that.)
Per report from Qingqing Zhou. The added regression test case is based
on his example.
This has been broken for a very long time, so back-patch to all active
branches.
Branch
------
REL9_1_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/3b5d67102789e1202d35fbbcb4b3f1a1c181cc02
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 67 +++++++++++++++++++++++++++-------
src/test/regress/expected/join.out | 48 ++++++++++++++++++++++++
src/test/regress/sql/join.sql | 20 ++++++++++
3 files changed, 121 insertions(+), 14 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] 11+ messages in thread
* pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-04 23:55 Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Tom Lane @ 2015-04-04 23:55 UTC (permalink / raw)
To: pgsql-committers
Fix incorrect matching of subexpressions in outer-join plan nodes.
Previously we would re-use input subexpressions in all expression trees
attached to a Join plan node. However, if it's an outer join and the
subexpression appears in the nullable-side input, this is potentially
incorrect for apparently-matching subexpressions that came from above
the outer join (ie, targetlist and qpqual expressions), because the
executor will treat the subexpression value as NULL when maybe it should
not be.
The case is fairly hard to hit because (a) you need a non-strict
subexpression (else NULL is correct), and (b) we don't usually compute
expressions in the outputs of non-toplevel plan nodes. But we might do
so if the expressions are sort keys for a mergejoin, for example.
Probably in the long run we should make a more explicit distinction between
Vars appearing above and below an outer join, but that will be a major
planner redesign and not at all back-patchable. For the moment, just hack
set_join_references so that it will not match any non-Var expressions
coming from nullable inputs to expressions that came from above the join.
(This is somewhat overkill, in that a strict expression could still be
matched, but it doesn't seem worth the effort to check that.)
Per report from Qingqing Zhou. The added regression test case is based
on his example.
This has been broken for a very long time, so back-patch to all active
branches.
Branch
------
REL9_0_STABLE
Details
-------
http://git.postgresql.org/pg/commitdiff/da88191945c49159d2f6354f75d5cdc2ba5d36d5
Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 67 +++++++++++++++++++++++++++-------
src/test/regress/expected/join.out | 48 ++++++++++++++++++++++++
src/test/regress/sql/join.sql | 20 ++++++++++
3 files changed, 121 insertions(+), 14 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] 11+ messages in thread
* Re: pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-06 21:43 Qingqing Zhou <zhouqq.postgres@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Qingqing Zhou @ 2015-04-06 21:43 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers
On Sat, Apr 4, 2015 at 4:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> planner redesign and not at all back-patchable. For the moment, just hack
> set_join_references so that it will not match any non-Var expressions
> coming from nullable inputs to expressions that came from above the join.
> (This is somewhat overkill, in that a strict expression could still be
> matched, but it doesn't seem worth the effort to check that.)
>
Just curious, checking an expression strictness is convenient in
build_tlist_index() like this:
TargetEntry *tle = (TargetEntry *) lfirst(l);
+ if (contain_nonstrict_functions((Node *)tle))
+ *hasnonstrict = true;
+
And this will almost avoid the overkill at once. Why not do this?
Thanks,
Qingqing
--
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] 11+ messages in thread
* Re: pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-06 23:22 Tom Lane <tgl@sss.pgh.pa.us>
parent: Qingqing Zhou <zhouqq.postgres@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Tom Lane @ 2015-04-06 23:22 UTC (permalink / raw)
To: Qingqing Zhou <zhouqq.postgres@gmail.com>; +Cc: pgsql-committers
Qingqing Zhou <zhouqq.postgres@gmail.com> writes:
> On Sat, Apr 4, 2015 at 4:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> (This is somewhat overkill, in that a strict expression could still be
>> matched, but it doesn't seem worth the effort to check that.)
> Just curious, checking an expression strictness is convenient in
> build_tlist_index() like this:
> TargetEntry *tle = (TargetEntry *) lfirst(l);
> + if (contain_nonstrict_functions((Node *)tle))
> + *hasnonstrict = true;
> +
> And this will almost avoid the overkill at once. Why not do this?
Because it's expensive (a syscache lookup per function or operator).
And that test alone would be insufficient anyway: you'd also have to
check that there was an appropriate Var in the expression, cf the
comment for contain_nonstrict_functions.
regards, tom lane
--
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] 11+ messages in thread
* Re: pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-07 00:11 Qingqing Zhou <zhouqq.postgres@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 11+ messages in thread
From: Qingqing Zhou @ 2015-04-07 00:11 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers
On Mon, Apr 6, 2015 at 4:22 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Because it's expensive (a syscache lookup per function or operator).
> And that test alone would be insufficient anyway: you'd also have to
> check that there was an appropriate Var in the expression, cf the
> comment for contain_nonstrict_functions.
>
Looks like not only contain_nonstrict_functions() is expensive, but
other contain_xxx family members.
In FuncExpr structure, for example, we already cached values like
retset, resulttype, but why not volatile and isstrict? In this way, we
avoid cache lookup every time. So as OpExpr etc.
Regards,
Qingqing
--
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] 11+ messages in thread
* Re: pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-24 17:30 Tom Lane <tgl@sss.pgh.pa.us>
parent: Qingqing Zhou <zhouqq.postgres@gmail.com>
0 siblings, 1 reply; 11+ messages in thread
From: Tom Lane @ 2015-04-24 17:30 UTC (permalink / raw)
To: Qingqing Zhou <zhouqq.postgres@gmail.com>; +Cc: pgsql-committers
[ catching up on email post-vacation ]
Qingqing Zhou <zhouqq.postgres@gmail.com> writes:
> On Mon, Apr 6, 2015 at 4:22 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Because it's expensive (a syscache lookup per function or operator).
>> And that test alone would be insufficient anyway: you'd also have to
>> check that there was an appropriate Var in the expression, cf the
>> comment for contain_nonstrict_functions.
> Looks like not only contain_nonstrict_functions() is expensive, but
> other contain_xxx family members.
> In FuncExpr structure, for example, we already cached values like
> retset, resulttype, but why not volatile and isstrict? In this way, we
> avoid cache lookup every time. So as OpExpr etc.
The reason we don't store those in the expression tree is that changing
those properties (eg with CREATE OR REPLACE FUNCTION) would break stored
views referencing the function. It's okay to store resulttype and retset
because we disallow changing the output type (including set-ness) of a
function; but we don't want to disallow changing strictness for instance.
regards, tom lane
--
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] 11+ messages in thread
* Re: pgsql: Fix incorrect matching of subexpressions in outer-join plan node
@ 2015-04-24 21:12 Andres Freund <andres@anarazel.de>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 11+ messages in thread
From: Andres Freund @ 2015-04-24 21:12 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Qingqing Zhou <zhouqq.postgres@gmail.com>; pgsql-committers
On 2015-04-24 13:30:49 -0400, Tom Lane wrote:
> [ catching up on email post-vacation ]
Welcome back Tom! Hope you had a nice and relaxing time.
> It's okay to store resulttype and retset
> because we disallow changing the output type (including set-ness) of a
> function; but we don't want to disallow changing strictness for
> instance.
I don't think we forbid changing the volatility. I'm pretty sure I've
changed that using CREATE OR REPLACE in the past.
Yep:
postgres[l]=# CREATE FUNCTION blarg() RETURNS int VOLATILE LANGUAGE SQL AS $$SELECT 1;$$;
CREATE FUNCTION
postgres[l]=# CREATE OR REPLACE FUNCTION blarg() RETURNS int STABLE LANGUAGE SQL AS $$SELECT 1;$$;
CREATE FUNCTION
Greetings,
Andres Freund
--
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] 11+ messages in thread
end of thread, other threads:[~2015-04-24 21:12 UTC | newest]
Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-04-04 23:55 pgsql: Fix incorrect matching of subexpressions in outer-join plan node Tom Lane <tgl@sss.pgh.pa.us>
2015-04-06 21:43 ` Qingqing Zhou <zhouqq.postgres@gmail.com>
2015-04-06 23:22 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-04-07 00:11 ` Qingqing Zhou <zhouqq.postgres@gmail.com>
2015-04-24 17:30 ` Tom Lane <tgl@sss.pgh.pa.us>
2015-04-24 21:12 ` Andres Freund <andres@anarazel.de>
2015-04-04 23:55 pgsql: Fix incorrect matching of subexpressions in outer-join plan node Tom Lane <tgl@sss.pgh.pa.us>
2015-04-04 23:55 pgsql: Fix incorrect matching of subexpressions in outer-join plan node Tom Lane <tgl@sss.pgh.pa.us>
2015-04-04 23:55 pgsql: Fix incorrect matching of subexpressions in outer-join plan node Tom Lane <tgl@sss.pgh.pa.us>
2015-04-04 23:55 pgsql: Fix incorrect matching of subexpressions in outer-join plan node Tom Lane <tgl@sss.pgh.pa.us>
2015-04-04 23:55 pgsql: Fix incorrect matching of subexpressions in outer-join plan node 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