postgresql/src/backend
Andres Freund 3fb307bc4a Reorder EPQ work, to fix rowmark related bugs and improve efficiency.
In ad0bda5d24 I changed the EvalPlanQual machinery to store
substitution tuples in slot, instead of using plain HeapTuples. The
main motivation for that was that using HeapTuples will be inefficient
for future tableams.  But it turns out that that conversion was buggy
for non-locking rowmarks - the wrong tuple descriptor was used to
create the slot.

As a secondary issue 5db6df0c0 changed ExecLockRows() to begin EPQ
earlier, to allow to fetch the locked rows directly into the EPQ
slots, instead of having to copy tuples around. Unfortunately, as Tom
complained, that forces some expensive initialization to happen
earlier.

As a third issue, the test coverage for EPQ was clearly insufficient.

Fixing the first issue is unfortunately not trivial: Non-locked row
marks were fetched at the start of EPQ, and we don't have the type
information for the rowmarks available at that point. While we could
change that, it's not easy. It might be worthwhile to change that at
some point, but to fix this bug, it seems better to delay fetching
non-locking rowmarks when they're actually needed, rather than
eagerly. They're referenced at most once, and in cases where EPQ
fails, might never be referenced. Fetching them when needed also
increases locality a bit.

To be able to fetch rowmarks during execution, rather than
initialization, we need to be able to access the active EPQState, as
that contains necessary data. To do so move EPQ related data from
EState to EPQState, and, only for EStates creates as part of EPQ,
reference the associated EPQState from EState.

To fix the second issue, change EPQ initialization to allow use of
EvalPlanQualSlot() to be used before EvalPlanQualBegin() (but
obviously still requiring EvalPlanQualInit() to have been done).

As these changes made struct EState harder to understand, e.g. by
adding multiple EStates, significantly reorder the members, and add a
lot more comments.

Also add a few more EPQ tests, including one that fails for the first
issue above. More is needed.

Reported-By: yi huang
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion:
    https://postgr.es/m/CAHU7rYZo_C4ULsAx_LAj8az9zqgrD8WDd4hTegDTMM1LMqrBsg@mail.gmail.com
    https://postgr.es/m/24530.1562686693@sss.pgh.pa.us
Backpatch: 12-, where the EPQ changes were introduced
2019-09-09 05:21:30 -07:00
..
access Fix handling of NULL distances in KNN-GiST 2019-09-08 21:17:37 +03:00
bootstrap In bootstrap mode, use default signal handling for SIGINT etc. 2019-05-14 10:22:28 -04:00
catalog Require the schema qualification in pg_temp.type_name(arg). 2019-08-05 07:48:45 -07:00
commands Reorder EPQ work, to fix rowmark related bugs and improve efficiency. 2019-09-09 05:21:30 -07:00
executor Reorder EPQ work, to fix rowmark related bugs and improve efficiency. 2019-09-09 05:21:30 -07:00
foreign Update copyright for 2019 2019-01-02 12:44:25 -05:00
jit Don't rely on llvm::make_unique. 2019-08-25 14:46:29 +12:00
lib Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
libpq Remove superfluous newlines in function prototypes. 2019-07-31 00:07:09 -07:00
main Replace @postgresql.org with @lists.postgresql.org for mailinglists 2019-01-19 19:06:35 +01:00
nodes Fix representation of hash keys in Hash/HashJoin nodes. 2019-08-02 00:02:49 -07:00
optimizer Fix representation of hash keys in Hash/HashJoin nodes. 2019-08-02 00:02:49 -07:00
parser Require the schema qualification in pg_temp.type_name(arg). 2019-08-05 07:48:45 -07:00
partitioning Avoid using INFO elevel for what are fundamentally debug messages. 2019-09-07 19:03:11 -04:00
po Translation updates 2019-09-09 11:34:06 +02:00
port Update stale comments, and fix comment typos. 2019-06-08 10:12:26 -07:00
postmaster Fix thinko when ending progress report for a backend 2019-09-04 15:46:45 +09:00
regex Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
replication Fix RelationIdGetRelation calls that weren't bothering with error checks. 2019-09-08 17:00:52 -04:00
rewrite Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
snowball Update copyright for 2019 2019-01-02 12:44:25 -05:00
statistics Use column collation for extended statistics 2019-07-20 16:35:15 +02:00
storage Remove superfluous newlines in function prototypes. 2019-07-31 00:07:09 -07:00
tcop Revert "Add log_statement_sample_rate parameter" 2019-08-04 23:37:44 +02:00
tsearch Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
utils Fix handling of non-key columns get_index_column_opclass() 2019-09-09 14:02:40 +03: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 Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
nls.mk Translation updates 2019-05-20 16:00:53 +02:00