postgresql/contrib
Alvaro Herrera 27846f02c1 Optimize locking a tuple already locked by another subxact
Locking and updating the same tuple repeatedly led to some strange
multixacts being created which had several subtransactions of the same
parent transaction holding locks of the same strength.  However,
once a subxact of the current transaction holds a lock of a given
strength, it's not necessary to acquire the same lock again.  This made
some coding patterns much slower than required.

The fix is twofold.  First we change HeapTupleSatisfiesUpdate to return
HeapTupleBeingUpdated for the case where the current transaction is
already a single-xid locker for the given tuple; it used to return
HeapTupleMayBeUpdated for that case.  The new logic is simpler, and the
change to pgrowlocks is a testament to that: previously we needed to
check for the single-xid locker separately in a very ugly way.  That
test is simpler now.

As fallout from the HTSU change, some of its callers need to be amended
so that tuple-locked-by-own-transaction is taken into account in the
BeingUpdated case rather than the MayBeUpdated case.  For many of them
there is no difference; but heap_delete() and heap_update now check
explicitely and do not grab tuple lock in that case.

The HTSU change also means that routine MultiXactHasRunningRemoteMembers
introduced in commit 11ac4c73cb is no longer necessary and can be
removed; the case that used to require it is now handled naturally as
result of the changes to heap_delete and heap_update.

The second part of the fix to the performance issue is to adjust
heap_lock_tuple to avoid the slowness:

1. Previously we checked for the case that our own transaction already
held a strong enough lock and returned MayBeUpdated, but only in the
multixact case.  Now we do it for the plain Xid case as well, which
saves having to LockTuple.

2. If the current transaction is the only locker of the tuple (but with
a lock not as strong as what we need; otherwise it would have been
caught in the check mentioned above), we can skip sleeping on the
multixact, and instead go straight to create an updated multixact with
the additional lock strength.

3. Most importantly, make sure that both the single-xid-locker case and
the multixact-locker case optimization are applied always.  We do this
by checking both in a single place, rather than them appearing in two
separate portions of the routine -- something that is made possible by
the HeapTupleSatisfiesUpdate API change.  Previously we would only check
for the single-xid case when HTSU returned MayBeUpdated, and only
checked for the multixact case when HTSU returned BeingUpdated.  This
was at odds with what HTSU actually returned in one case: if our own
transaction was locker in a multixact, it returned MayBeUpdated, so the
optimization never applied.  This is what led to the large multixacts in
the first place.

Per bug report #8470 by Oskari Saarenmaa.
2015-04-10 13:47:15 -03:00
..
adminpack Update copyright for 2015 2015-01-06 11:43:47 -05:00
auth_delay Add file version information to most installed Windows binaries. 2014-07-14 14:07:52 -04:00
auto_explain Rearrange explain.c's API so callers need not embed sizeof(ExplainState). 2015-01-15 13:39:33 -05:00
btree_gin btree_gin: properly call DirectFunctionCall1() 2015-03-31 10:26:45 -04:00
btree_gist Define integer limits independently from the system definitions. 2015-04-02 17:43:35 +02:00
chkpass Avoid returning undefined bytes in chkpass_in(). 2015-02-14 12:20:56 -05:00
citext Fix citext upgrade script for disallowance of oidvector element assignment. 2014-08-28 18:21:05 -04:00
cube Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
dblink Fix volatile-safety issue in dblink's materializeQueryResult(). 2015-01-26 15:17:33 -05:00
dict_int Update copyright for 2015 2015-01-06 11:43:47 -05:00
dict_xsyn Update copyright for 2015 2015-01-06 11:43:47 -05:00
earthdistance Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
file_fdw Allow foreign tables to participate in inheritance. 2015-03-22 13:53:21 -04:00
fuzzystrmatch Remove dead code. 2015-02-03 09:43:44 +02:00
hstore Use FLEXIBLE_ARRAY_MEMBER in a number of other places. 2015-02-21 16:12:14 -05:00
intagg Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
intarray Centralize definition of integer limits. 2015-03-25 22:39:42 +01:00
isn Replace a bunch more uses of strncpy() with safer coding. 2015-01-24 13:05:42 -05:00
lo Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
ltree Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
oid2name Add file version information to most installed Windows binaries. 2014-07-14 14:07:52 -04:00
pageinspect Move BRIN page type to page's last two bytes 2015-03-10 12:27:15 -03:00
passwordcheck Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_archivecleanup Replace a few strncmp() calls with strlcpy(). 2014-08-18 22:59:31 -04:00
pg_buffercache Align buffer descriptors to cache line boundaries. 2015-01-29 22:48:45 +01:00
pg_freespacemap Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
pg_prewarm Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_standby pg_standby: Avoid writing one byte beyond the end of the buffer. 2015-01-15 09:26:03 -05:00
pg_stat_statements Better fix for misuse of Float8GetDatumFast(). 2015-03-28 13:56:37 -04:00
pg_test_fsync Avoid file descriptor leak in pg_test_fsync. 2014-11-19 12:06:24 -05:00
pg_test_timing Correctly handle test durations of more than 2147s in pg_test_timing. 2015-01-04 15:44:49 +01:00
pg_trgm Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
pg_upgrade pg_upgrade: call 'postgres' binary to get data directory location 2015-04-01 18:25:45 -04:00
pg_upgrade_support Update copyright for 2015 2015-01-06 11:43:47 -05:00
pg_xlogdump Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
pgbench Improve pgbench error reporting. 2015-04-02 16:26:49 -04:00
pgcrypto Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
pgrowlocks Optimize locking a tuple already locked by another subxact 2015-04-10 13:47:15 -03:00
pgstattuple Fix typos in some error messages thrown by extension scripts when fed to psql. 2014-08-25 18:30:37 +02:00
postgres_fdw Remove spurious semicolons. 2015-03-31 15:12:27 +03:00
seg Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
sepgsql sepgsql: Improve error message when unsupported object type is labeled. 2015-03-11 12:12:10 -04:00
spi Use FLEXIBLE_ARRAY_MEMBER in a number of other places. 2015-02-21 16:12:14 -05:00
sslinfo Make Port->ssl_in_use available, even when built with !USE_SSL 2014-11-25 09:46:11 +02:00
start-scripts doc: Reflect renaming of Mac OS X to OS X 2014-09-09 13:56:29 -04:00
tablefunc Handle unexpected query results, especially NULLs, safely in connectby(). 2015-01-29 20:18:33 -05:00
tcn Update copyright for 2015 2015-01-06 11:43:47 -05:00
test_decoding Update copyright for 2015 2015-01-06 11:43:47 -05:00
tsearch2 Update copyright for 2015 2015-01-06 11:43:47 -05:00
unaccent Update copyright for 2015 2015-01-06 11:43:47 -05:00
uuid-ossp Update copyright for 2015 2015-01-06 11:43:47 -05:00
vacuumlo vacuumlo: Avoid unlikely memory leak. 2015-01-14 15:14:20 -05:00
xml2 Replace a bunch more uses of strncpy() with safer coding. 2015-01-24 13:05:42 -05:00
contrib-global.mk Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
Makefile Move test modules from contrib to src/test/modules 2014-11-29 23:55:00 -03:00
README Rename 'gmake' to 'make' in docs and recommended commands 2014-02-12 17:29:19 -05:00

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.