postgresql/src/backend
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
..
access Attach FPI to the first record after full_page_writes is turned on. 2018-09-13 15:32:50 +05:30
bootstrap Install a check for mis-linking of src/port and src/common functions. 2018-09-09 12:23:23 -04:00
catalog Simplify index tuple descriptor initialization 2018-09-13 08:22:03 +02:00
commands Fix ALTER/TYPE on columns referenced by FKs in partitioned tables 2018-09-14 13:41:20 -03:00
executor Fix failure with initplans used conditionally during EvalPlanQual rechecks. 2018-09-15 13:42:33 -04:00
foreign Remove bogus "extern" annotations on function definitions. 2018-02-19 12:07:44 -05:00
jit LLVMJIT: LLVMGetHostCPUFeatures now is upstream, use LLMV version if available. 2018-08-24 10:21:38 -07:00
lib doc: Update redirecting links 2018-07-16 10:48:05 +02:00
libpq Minor cleanup/future-proofing for pg_saslprep(). 2018-09-08 18:20:36 -04:00
main Update copyright for 2018 2018-01-02 23:30:12 -05:00
nodes Order active window clauses for greater reuse of Sort nodes. 2018-09-14 17:35:42 +01:00
optimizer Order active window clauses for greater reuse of Sort nodes. 2018-09-14 17:35:42 +01:00
parser Fully enforce uniqueness of constraint names. 2018-09-04 13:45:35 -04:00
partitioning Remove duplicated words split across lines in comments 2018-09-08 12:24:19 -07:00
po Translation updates 2018-06-25 12:37:18 +02:00
port Refactor dlopen() support 2018-09-06 11:33:04 +02:00
postmaster Refactor dlopen() support 2018-09-06 11:33:04 +02:00
regex Clean up warnings from -Wimplicit-fallthrough. 2018-05-01 19:35:08 -04:00
replication Improve some error message strings and errcodes 2018-09-04 11:06:04 -07:00
rewrite Fix set of NLS translation issues 2018-08-21 15:17:13 +09:00
snowball Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00
statistics Fix typos. 2018-08-27 09:32:59 +12:00
storage Remove duplicated words split across lines in comments 2018-09-08 12:24:19 -07:00
tcop Introduce minimal C99 usage to verify compiler support. 2018-08-23 18:36:07 -07:00
tsearch Hand code string to integer conversion for performance. 2018-07-22 14:58:23 -07:00
utils Repair bug in regexp split performance improvements. 2018-09-12 19:31:06 +01:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Refactor dlopen() support 2018-09-06 11:33:04 +02:00
nls.mk Translation updates 2018-06-25 12:37:18 +02:00