postgresql/src
Tom Lane 1f4a920b73 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
2018-09-15 13:42:33 -04:00
..
backend Fix failure with initplans used conditionally during EvalPlanQual rechecks. 2018-09-15 13:42:33 -04:00
bin Improve parallel scheduling logic in pg_dump/pg_restore. 2018-09-14 17:31:51 -04:00
common Allow concurrent-safe open() and fopen() in frontend code for Windows 2018-09-14 10:04:14 +09:00
fe_utils Fix lexing of standard multi-character operators in edge cases. 2018-08-23 21:42:40 +01:00
include Fix failure with initplans used conditionally during EvalPlanQual rechecks. 2018-09-15 13:42:33 -04:00
interfaces Attempt to identify system timezone by reading /etc/localtime symlink. 2018-09-13 12:36:21 -04:00
makefiles Refactor installation of extension headers. 2018-09-07 14:19:14 +01:00
pl Use C99 designated initializers for some structs 2018-09-07 11:40:03 +02:00
port Fix inconsistent argument naming. 2018-09-06 11:14:22 -04:00
template Force "restrict" not to be used when compiling with xlc. 2017-10-13 12:15:06 -07:00
test Fix failure with initplans used conditionally during EvalPlanQual rechecks. 2018-09-15 13:42:33 -04:00
timezone Update time zone data files to tzdata release 2018e. 2018-05-09 13:56:22 -04:00
tools Install a check for mis-linking of src/port and src/common functions. 2018-09-09 12:23:23 -04:00
tutorial Deduplicate "invalid input syntax" messages for various types. 2018-07-22 14:58:01 -07:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Fix partial-build problems introduced by having more generated headers. 2018-04-09 16:42:10 -04:00
Makefile.global.in Ensure we build generated headers at the start of some more cases. 2018-07-30 18:04:39 -04:00
Makefile.shlib Use -Bsymbolic for shared libraries on HP-UX and Solaris. 2018-09-10 22:22:12 -04:00
nls-global.mk nls-global.mk: search build dir for source files, too 2016-06-07 18:55:18 -04:00