postgresql/src/backend
Andres Freund 5db6df0c01 tableam: Add tuple_{insert, delete, update, lock} and use.
This adds new, required, table AM callbacks for insert/delete/update
and lock_tuple. To be able to reasonably use those, the EvalPlanQual
mechanism had to be adapted, moving more logic into the AM.

Previously both delete/update/lock call-sites and the EPQ mechanism had
to have awareness of the specific tuple format to be able to fetch the
latest version of a tuple. Obviously that needs to be abstracted
away. To do so, move the logic that find the latest row version into
the AM. lock_tuple has a new flag argument,
TUPLE_LOCK_FLAG_FIND_LAST_VERSION, that forces it to lock the last
version, rather than the current one.  It'd have been possible to do
so via a separate callback as well, but finding the last version
usually also necessitates locking the newest version, making it
sensible to combine the two. This replaces the previous use of
EvalPlanQualFetch().  Additionally HeapTupleUpdated, which previously
signaled either a concurrent update or delete, is now split into two,
to avoid callers needing AM specific knowledge to differentiate.

The move of finding the latest row version into tuple_lock means that
encountering a row concurrently moved into another partition will now
raise an error about "tuple to be locked" rather than "tuple to be
updated/deleted" - which is accurate, as that always happens when
locking rows. While possible slightly less helpful for users, it seems
like an acceptable trade-off.

As part of this commit HTSU_Result has been renamed to TM_Result, and
its members been expanded to differentiated between updating and
deleting. HeapUpdateFailureData has been renamed to TM_FailureData.

The interface to speculative insertion is changed so nodeModifyTable.c
does not have to set the speculative token itself anymore. Instead
there's a version of tuple_insert, tuple_insert_speculative, that
performs the speculative insertion (without requiring a flag to signal
that fact), and the speculative insertion is either made permanent
with table_complete_speculative(succeeded = true) or aborted with
succeeded = false).

Note that multi_insert is not yet routed through tableam, nor is
COPY. Changing multi_insert requires changes to copy.c that are large
enough to better be done separately.

Similarly, although simpler, CREATE TABLE AS and CREATE MATERIALIZED
VIEW are also only going to be adjusted in a later commit.

Author: Andres Freund and Haribabu Kommi
Discussion:
    https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
    https://postgr.es/m/20190313003903.nwvrxi7rw3ywhdel@alap3.anarazel.de
    https://postgr.es/m/20160812231527.GA690404@alvherre.pgsql
2019-03-23 19:55:57 -07:00
..
access tableam: Add tuple_{insert, delete, update, lock} and use. 2019-03-23 19:55:57 -07:00
bootstrap tableam: Add and use scan APIs. 2019-03-11 12:46:41 -07:00
catalog Collations with nondeterministic comparison 2019-03-22 12:12:43 +01:00
commands tableam: Add tuple_{insert, delete, update, lock} and use. 2019-03-23 19:55:57 -07:00
executor tableam: Add tuple_{insert, delete, update, lock} and use. 2019-03-23 19:55:57 -07:00
foreign Update copyright for 2019 2019-01-02 12:44:25 -05:00
jit Renaming for new subscripting mechanism 2019-02-01 12:50:32 -03:00
lib Fix yet more portability bugs in integerset and its tests. 2019-03-22 17:59:19 +02:00
libpq Add DNS SRV support for LDAP server discovery. 2019-03-21 15:28:17 +13:00
main Replace @postgresql.org with @lists.postgresql.org for mailinglists 2019-01-19 19:06:35 +01:00
nodes Collations with nondeterministic comparison 2019-03-22 12:12:43 +01:00
optimizer Don't copy PartitionBoundInfo in set_relation_partition_info. 2019-03-22 14:16:58 -04:00
parser Add unreachable "break" to satisfy -Wimplicit-fallthrough. 2019-03-23 01:32:58 -04:00
partitioning Rearrange make_partitionedrel_pruneinfo to avoid work when we can't prune. 2019-03-22 14:56:12 -04:00
po Translation updates 2018-06-25 12:37:18 +02:00
port Add shared_memory_type GUC. 2019-02-03 12:47:26 +01:00
postmaster Make checkpoint requests more robust. 2019-03-19 12:49:27 -04:00
regex Collations with nondeterministic comparison 2019-03-22 12:12:43 +01:00
replication Add walreceiver API to get remote server version 2019-03-15 10:16:26 +01:00
rewrite tableam: Add and use scan APIs. 2019-03-11 12:46:41 -07:00
snowball Update copyright for 2019 2019-01-02 12:44:25 -05:00
statistics Rename nodes/relation.h to nodes/pathnodes.h. 2019-01-29 16:49:25 -05:00
storage Improve code comments in b0eaa4c51b. 2019-03-16 06:55:56 +05:30
tcop Implement OR REPLACE option for CREATE AGGREGATE. 2019-03-19 01:16:50 +00:00
tsearch Move hash_any prototype from access/hash.h to utils/hashutils.h 2019-03-11 13:17:50 -03:00
utils Remove inadequate check for duplicate "xml" PI. 2019-03-23 17:40:19 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Get rid of jsonpath_gram.h and jsonpath_scanner.h 2019-03-20 11:13:34 +03:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2018-06-25 12:37:18 +02:00