pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix failure with initplans used conditionally during EvalPlanQua
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix failure with initplans used conditionally during EvalPlanQua
@ 2018-09-15 17:43  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2018-09-15 17:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix failure with initplans used conditionally during EvalPlanQual rechecks.

The EvalPlanQual machinery assumes that any initplans (that is,
uncorrelated sub-selects) used during an EPQ recheck would have already
been evaluated during the main query; this is implicit in the fact that
execPlan pointers are not copied into the EPQ estate's es_param_exec_vals.
But it's possible for that assumption to fail, if the initplan is only
reached conditionally.  For example, a sub-select inside a CASE expression
could be reached during a recheck when it had not been previously, if the
CASE test depends on a column that was just updated.

This bug is old, appearing to date back to my rewrite of EvalPlanQual in
commit 9f2ee8f28, but was not detected until Kyle Samson reported a case.

To fix, force all not-yet-evaluated initplans used within the EPQ plan
subtree to be evaluated at the start of the recheck, before entering the
EPQ environment.  This could be inefficient, if such an initplan is
expensive and goes unused again during the recheck --- but that's piling
one layer of improbability atop another.  It doesn't seem worth adding
more complexity to prevent that, at least not in the back branches.

It was convenient to use the new-in-v11 ExecEvalParamExecParams function
to implement this, but I didn't like either its name or the specifics of
its API, so revise that.

Back-patch all the way.  Rather than rewrite the patch to avoid depending
on bms_next_member() in the oldest branches, I chose to back-patch that
function into 9.4 and 9.3.  (This isn't the first time back-patches have
needed that, and it exhausted my patience.)  I also chose to back-patch
some test cases added by commits 71404af2a and 342a1ffa2 into 9.4 and 9.3,
so that the 9.x versions of eval-plan-qual.spec are all the same.

Andrew Gierth diagnosed the problem and contributed the added test cases,
though the actual code changes are by me.

Discussion: https://postgr.es/m/A033A40A-B234-4324-BE37-272279F7B627@tripadvisor.com

Branch
------
REL9_4_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8494755109e97ad22c9817b9dbe550b535961ed4

Modified Files
--------------
src/backend/executor/execMain.c                | 39 ++++++++++-
src/backend/executor/nodeSubplan.c             | 42 ++++++++++++
src/backend/nodes/bitmapset.c                  | 68 +++++++++++++++++--
src/include/executor/nodeSubplan.h             |  2 +
src/include/nodes/bitmapset.h                  |  1 +
src/test/isolation/expected/eval-plan-qual.out | 90 ++++++++++++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec   | 50 ++++++++++++++
7 files changed, 285 insertions(+), 7 deletions(-)



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

* pgsql: Fix failure with initplans used conditionally during EvalPlanQua
@ 2018-09-15 17:43  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2018-09-15 17:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix failure with initplans used conditionally during EvalPlanQual rechecks.

The EvalPlanQual machinery assumes that any initplans (that is,
uncorrelated sub-selects) used during an EPQ recheck would have already
been evaluated during the main query; this is implicit in the fact that
execPlan pointers are not copied into the EPQ estate's es_param_exec_vals.
But it's possible for that assumption to fail, if the initplan is only
reached conditionally.  For example, a sub-select inside a CASE expression
could be reached during a recheck when it had not been previously, if the
CASE test depends on a column that was just updated.

This bug is old, appearing to date back to my rewrite of EvalPlanQual in
commit 9f2ee8f28, but was not detected until Kyle Samson reported a case.

To fix, force all not-yet-evaluated initplans used within the EPQ plan
subtree to be evaluated at the start of the recheck, before entering the
EPQ environment.  This could be inefficient, if such an initplan is
expensive and goes unused again during the recheck --- but that's piling
one layer of improbability atop another.  It doesn't seem worth adding
more complexity to prevent that, at least not in the back branches.

It was convenient to use the new-in-v11 ExecEvalParamExecParams function
to implement this, but I didn't like either its name or the specifics of
its API, so revise that.

Back-patch all the way.  Rather than rewrite the patch to avoid depending
on bms_next_member() in the oldest branches, I chose to back-patch that
function into 9.4 and 9.3.  (This isn't the first time back-patches have
needed that, and it exhausted my patience.)  I also chose to back-patch
some test cases added by commits 71404af2a and 342a1ffa2 into 9.4 and 9.3,
so that the 9.x versions of eval-plan-qual.spec are all the same.

Andrew Gierth diagnosed the problem and contributed the added test cases,
though the actual code changes are by me.

Discussion: https://postgr.es/m/A033A40A-B234-4324-BE37-272279F7B627@tripadvisor.com

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/99cbbbbd1ddd3eb23dba7d0f4810e5accccce8c8

Modified Files
--------------
src/backend/executor/execMain.c                | 47 ++++++++++++++++++++++----
src/backend/executor/nodeSubplan.c             | 42 +++++++++++++++++++++++
src/include/executor/nodeSubplan.h             |  2 ++
src/test/isolation/expected/eval-plan-qual.out | 31 +++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec   | 17 ++++++++++
5 files changed, 133 insertions(+), 6 deletions(-)



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

* pgsql: Fix failure with initplans used conditionally during EvalPlanQua
@ 2018-09-15 17:43  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2018-09-15 17:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix failure with initplans used conditionally during EvalPlanQual rechecks.

The EvalPlanQual machinery assumes that any initplans (that is,
uncorrelated sub-selects) used during an EPQ recheck would have already
been evaluated during the main query; this is implicit in the fact that
execPlan pointers are not copied into the EPQ estate's es_param_exec_vals.
But it's possible for that assumption to fail, if the initplan is only
reached conditionally.  For example, a sub-select inside a CASE expression
could be reached during a recheck when it had not been previously, if the
CASE test depends on a column that was just updated.

This bug is old, appearing to date back to my rewrite of EvalPlanQual in
commit 9f2ee8f28, but was not detected until Kyle Samson reported a case.

To fix, force all not-yet-evaluated initplans used within the EPQ plan
subtree to be evaluated at the start of the recheck, before entering the
EPQ environment.  This could be inefficient, if such an initplan is
expensive and goes unused again during the recheck --- but that's piling
one layer of improbability atop another.  It doesn't seem worth adding
more complexity to prevent that, at least not in the back branches.

It was convenient to use the new-in-v11 ExecEvalParamExecParams function
to implement this, but I didn't like either its name or the specifics of
its API, so revise that.

Back-patch all the way.  Rather than rewrite the patch to avoid depending
on bms_next_member() in the oldest branches, I chose to back-patch that
function into 9.4 and 9.3.  (This isn't the first time back-patches have
needed that, and it exhausted my patience.)  I also chose to back-patch
some test cases added by commits 71404af2a and 342a1ffa2 into 9.4 and 9.3,
so that the 9.x versions of eval-plan-qual.spec are all the same.

Andrew Gierth diagnosed the problem and contributed the added test cases,
though the actual code changes are by me.

Discussion: https://postgr.es/m/A033A40A-B234-4324-BE37-272279F7B627@tripadvisor.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1f4a920b7309499d2d0c4ceda5e6356e10bc51da

Modified Files
--------------
src/backend/executor/execExprInterp.c          | 27 -----------------
src/backend/executor/execMain.c                | 40 +++++++++++++++++++++---
src/backend/executor/execParallel.c            | 24 ++++++++++++---
src/backend/executor/nodeSubplan.c             | 42 ++++++++++++++++++++++++++
src/include/executor/execExpr.h                |  1 -
src/include/executor/nodeSubplan.h             |  2 ++
src/test/isolation/expected/eval-plan-qual.out | 31 +++++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec   | 17 +++++++++++
8 files changed, 147 insertions(+), 37 deletions(-)



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

* pgsql: Fix failure with initplans used conditionally during EvalPlanQua
@ 2018-09-15 17:43  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2018-09-15 17:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix failure with initplans used conditionally during EvalPlanQual rechecks.

The EvalPlanQual machinery assumes that any initplans (that is,
uncorrelated sub-selects) used during an EPQ recheck would have already
been evaluated during the main query; this is implicit in the fact that
execPlan pointers are not copied into the EPQ estate's es_param_exec_vals.
But it's possible for that assumption to fail, if the initplan is only
reached conditionally.  For example, a sub-select inside a CASE expression
could be reached during a recheck when it had not been previously, if the
CASE test depends on a column that was just updated.

This bug is old, appearing to date back to my rewrite of EvalPlanQual in
commit 9f2ee8f28, but was not detected until Kyle Samson reported a case.

To fix, force all not-yet-evaluated initplans used within the EPQ plan
subtree to be evaluated at the start of the recheck, before entering the
EPQ environment.  This could be inefficient, if such an initplan is
expensive and goes unused again during the recheck --- but that's piling
one layer of improbability atop another.  It doesn't seem worth adding
more complexity to prevent that, at least not in the back branches.

It was convenient to use the new-in-v11 ExecEvalParamExecParams function
to implement this, but I didn't like either its name or the specifics of
its API, so revise that.

Back-patch all the way.  Rather than rewrite the patch to avoid depending
on bms_next_member() in the oldest branches, I chose to back-patch that
function into 9.4 and 9.3.  (This isn't the first time back-patches have
needed that, and it exhausted my patience.)  I also chose to back-patch
some test cases added by commits 71404af2a and 342a1ffa2 into 9.4 and 9.3,
so that the 9.x versions of eval-plan-qual.spec are all the same.

Andrew Gierth diagnosed the problem and contributed the added test cases,
though the actual code changes are by me.

Discussion: https://postgr.es/m/A033A40A-B234-4324-BE37-272279F7B627@tripadvisor.com

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2a97a0ad34daefde117cc9001c97ad3c0ef82dfb

Modified Files
--------------
src/backend/executor/execMain.c                | 43 +++++++++++++++++++++++---
src/backend/executor/nodeSubplan.c             | 42 +++++++++++++++++++++++++
src/include/executor/nodeSubplan.h             |  2 ++
src/test/isolation/expected/eval-plan-qual.out | 31 +++++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec   | 17 ++++++++++
5 files changed, 131 insertions(+), 4 deletions(-)



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

* pgsql: Fix failure with initplans used conditionally during EvalPlanQua
@ 2018-09-15 17:43  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2018-09-15 17:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix failure with initplans used conditionally during EvalPlanQual rechecks.

The EvalPlanQual machinery assumes that any initplans (that is,
uncorrelated sub-selects) used during an EPQ recheck would have already
been evaluated during the main query; this is implicit in the fact that
execPlan pointers are not copied into the EPQ estate's es_param_exec_vals.
But it's possible for that assumption to fail, if the initplan is only
reached conditionally.  For example, a sub-select inside a CASE expression
could be reached during a recheck when it had not been previously, if the
CASE test depends on a column that was just updated.

This bug is old, appearing to date back to my rewrite of EvalPlanQual in
commit 9f2ee8f28, but was not detected until Kyle Samson reported a case.

To fix, force all not-yet-evaluated initplans used within the EPQ plan
subtree to be evaluated at the start of the recheck, before entering the
EPQ environment.  This could be inefficient, if such an initplan is
expensive and goes unused again during the recheck --- but that's piling
one layer of improbability atop another.  It doesn't seem worth adding
more complexity to prevent that, at least not in the back branches.

It was convenient to use the new-in-v11 ExecEvalParamExecParams function
to implement this, but I didn't like either its name or the specifics of
its API, so revise that.

Back-patch all the way.  Rather than rewrite the patch to avoid depending
on bms_next_member() in the oldest branches, I chose to back-patch that
function into 9.4 and 9.3.  (This isn't the first time back-patches have
needed that, and it exhausted my patience.)  I also chose to back-patch
some test cases added by commits 71404af2a and 342a1ffa2 into 9.4 and 9.3,
so that the 9.x versions of eval-plan-qual.spec are all the same.

Andrew Gierth diagnosed the problem and contributed the added test cases,
though the actual code changes are by me.

Discussion: https://postgr.es/m/A033A40A-B234-4324-BE37-272279F7B627@tripadvisor.com

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9b14bbd52c8caf5ac92b0e8088684fc72f070c33

Modified Files
--------------
src/backend/executor/execMain.c                | 39 ++++++++++++++++++++++--
src/backend/executor/nodeSubplan.c             | 42 ++++++++++++++++++++++++++
src/include/executor/nodeSubplan.h             |  2 ++
src/test/isolation/expected/eval-plan-qual.out | 31 +++++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec   | 17 +++++++++++
5 files changed, 129 insertions(+), 2 deletions(-)



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

* pgsql: Fix failure with initplans used conditionally during EvalPlanQua
@ 2018-09-15 17:43  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2018-09-15 17:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix failure with initplans used conditionally during EvalPlanQual rechecks.

The EvalPlanQual machinery assumes that any initplans (that is,
uncorrelated sub-selects) used during an EPQ recheck would have already
been evaluated during the main query; this is implicit in the fact that
execPlan pointers are not copied into the EPQ estate's es_param_exec_vals.
But it's possible for that assumption to fail, if the initplan is only
reached conditionally.  For example, a sub-select inside a CASE expression
could be reached during a recheck when it had not been previously, if the
CASE test depends on a column that was just updated.

This bug is old, appearing to date back to my rewrite of EvalPlanQual in
commit 9f2ee8f28, but was not detected until Kyle Samson reported a case.

To fix, force all not-yet-evaluated initplans used within the EPQ plan
subtree to be evaluated at the start of the recheck, before entering the
EPQ environment.  This could be inefficient, if such an initplan is
expensive and goes unused again during the recheck --- but that's piling
one layer of improbability atop another.  It doesn't seem worth adding
more complexity to prevent that, at least not in the back branches.

It was convenient to use the new-in-v11 ExecEvalParamExecParams function
to implement this, but I didn't like either its name or the specifics of
its API, so revise that.

Back-patch all the way.  Rather than rewrite the patch to avoid depending
on bms_next_member() in the oldest branches, I chose to back-patch that
function into 9.4 and 9.3.  (This isn't the first time back-patches have
needed that, and it exhausted my patience.)  I also chose to back-patch
some test cases added by commits 71404af2a and 342a1ffa2 into 9.4 and 9.3,
so that the 9.x versions of eval-plan-qual.spec are all the same.

Andrew Gierth diagnosed the problem and contributed the added test cases,
though the actual code changes are by me.

Discussion: https://postgr.es/m/A033A40A-B234-4324-BE37-272279F7B627@tripadvisor.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/f13e2d1cec9b786405d649c72a4aa29fadcea617

Modified Files
--------------
src/backend/executor/execExprInterp.c          | 27 -----------------
src/backend/executor/execMain.c                | 40 +++++++++++++++++++++---
src/backend/executor/execParallel.c            | 24 ++++++++++++---
src/backend/executor/nodeSubplan.c             | 42 ++++++++++++++++++++++++++
src/include/executor/execExpr.h                |  1 -
src/include/executor/nodeSubplan.h             |  2 ++
src/test/isolation/expected/eval-plan-qual.out | 31 +++++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec   | 17 +++++++++++
8 files changed, 147 insertions(+), 37 deletions(-)



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

* pgsql: Fix failure with initplans used conditionally during EvalPlanQua
@ 2018-09-15 17:43  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 7+ messages in thread

From: Tom Lane @ 2018-09-15 17:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix failure with initplans used conditionally during EvalPlanQual rechecks.

The EvalPlanQual machinery assumes that any initplans (that is,
uncorrelated sub-selects) used during an EPQ recheck would have already
been evaluated during the main query; this is implicit in the fact that
execPlan pointers are not copied into the EPQ estate's es_param_exec_vals.
But it's possible for that assumption to fail, if the initplan is only
reached conditionally.  For example, a sub-select inside a CASE expression
could be reached during a recheck when it had not been previously, if the
CASE test depends on a column that was just updated.

This bug is old, appearing to date back to my rewrite of EvalPlanQual in
commit 9f2ee8f28, but was not detected until Kyle Samson reported a case.

To fix, force all not-yet-evaluated initplans used within the EPQ plan
subtree to be evaluated at the start of the recheck, before entering the
EPQ environment.  This could be inefficient, if such an initplan is
expensive and goes unused again during the recheck --- but that's piling
one layer of improbability atop another.  It doesn't seem worth adding
more complexity to prevent that, at least not in the back branches.

It was convenient to use the new-in-v11 ExecEvalParamExecParams function
to implement this, but I didn't like either its name or the specifics of
its API, so revise that.

Back-patch all the way.  Rather than rewrite the patch to avoid depending
on bms_next_member() in the oldest branches, I chose to back-patch that
function into 9.4 and 9.3.  (This isn't the first time back-patches have
needed that, and it exhausted my patience.)  I also chose to back-patch
some test cases added by commits 71404af2a and 342a1ffa2 into 9.4 and 9.3,
so that the 9.x versions of eval-plan-qual.spec are all the same.

Andrew Gierth diagnosed the problem and contributed the added test cases,
though the actual code changes are by me.

Discussion: https://postgr.es/m/A033A40A-B234-4324-BE37-272279F7B627@tripadvisor.com

Branch
------
REL9_3_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/591d0ac8858c4f532a482c8f2f686c44d563b03d

Modified Files
--------------
src/backend/executor/execMain.c                | 39 ++++++++++-
src/backend/executor/nodeSubplan.c             | 42 ++++++++++++
src/backend/nodes/bitmapset.c                  | 68 +++++++++++++++++--
src/include/executor/nodeSubplan.h             |  2 +
src/include/nodes/bitmapset.h                  |  1 +
src/test/isolation/expected/eval-plan-qual.out | 90 ++++++++++++++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec   | 50 ++++++++++++++
7 files changed, 285 insertions(+), 7 deletions(-)



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


end of thread, other threads:[~2018-09-15 17:43 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-09-15 17:43 pgsql: Fix failure with initplans used conditionally during EvalPlanQua Tom Lane <tgl@sss.pgh.pa.us>
2018-09-15 17:43 pgsql: Fix failure with initplans used conditionally during EvalPlanQua Tom Lane <tgl@sss.pgh.pa.us>
2018-09-15 17:43 pgsql: Fix failure with initplans used conditionally during EvalPlanQua Tom Lane <tgl@sss.pgh.pa.us>
2018-09-15 17:43 pgsql: Fix failure with initplans used conditionally during EvalPlanQua Tom Lane <tgl@sss.pgh.pa.us>
2018-09-15 17:43 pgsql: Fix failure with initplans used conditionally during EvalPlanQua Tom Lane <tgl@sss.pgh.pa.us>
2018-09-15 17:43 pgsql: Fix failure with initplans used conditionally during EvalPlanQua Tom Lane <tgl@sss.pgh.pa.us>
2018-09-15 17:43 pgsql: Fix failure with initplans used conditionally during EvalPlanQua 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