postgresql/src/include/utils
Tom Lane 52f5d578d6 Create a function to reliably identify which sessions block which others.
This patch introduces "pg_blocking_pids(int) returns int[]", which returns
the PIDs of any sessions that are blocking the session with the given PID.
Historically people have obtained such information using a self-join on
the pg_locks view, but it's unreasonably tedious to do it that way with any
modicum of correctness, and the addition of parallel queries has pretty
much broken that approach altogether.  (Given some more columns in the view
than there are today, you could imagine handling parallel-query cases with
a 4-way join; but ugh.)

The new function has the following behaviors that are painful or impossible
to get right via pg_locks:

1. Correctly understands which lock modes block which other ones.

2. In soft-block situations (two processes both waiting for conflicting lock
modes), only the one that's in front in the wait queue is reported to
block the other.

3. In parallel-query cases, reports all sessions blocking any member of
the given PID's lock group, and reports a session by naming its leader
process's PID, which will be the pg_backend_pid() value visible to
clients.

The motivation for doing this right now is mostly to fix the isolation
tests.  Commit 38f8bdcac4 lobotomized
isolationtester's is-it-waiting query by removing its ability to recognize
nonconflicting lock modes, as a crude workaround for the inability to
handle soft-block situations properly.  But even without the lock mode
tests, the old query was excessively slow, particularly in
CLOBBER_CACHE_ALWAYS builds; some of our buildfarm animals fail the new
deadlock-hard test because the deadlock timeout elapses before they can
probe the waiting status of all eight sessions.  Replacing the pg_locks
self-join with use of pg_blocking_pids() is not only much more correct, but
a lot faster: I measure it at about 9X faster in a typical dev build with
Asserts, and 3X faster in CLOBBER_CACHE_ALWAYS builds.  That should provide
enough headroom for the slower CLOBBER_CACHE_ALWAYS animals to pass the
test, without having to lengthen deadlock_timeout yet more and thus slow
down the test for everyone else.
2016-02-22 14:31:43 -05:00
..
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
acl.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
aclchk_internal.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
array.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
arrayaccess.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
ascii.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
attoptcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
builtins.h Create a function to reliably identify which sessions block which others. 2016-02-22 14:31:43 -05:00
bytea.h Extend sortsupport for text to more opclasses. 2016-02-03 14:29:53 -05:00
cash.h Add casts from int4 and int8 to numeric. 2011-04-05 09:35:43 -04:00
catcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
combocid.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
date.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
datetime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
datum.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
dynahash.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
dynamic_loader.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
elog.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
evtcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
expandeddatum.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
fmgrtab.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
formatting.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
geo_decls.h Fix assorted inconsistencies in GiST opclass support function declarations. 2016-01-19 12:04:36 -05:00
guc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
guc_tables.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
help_config.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
hsearch.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
index_selfuncs.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
inet.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
int8.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
inval.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
json.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
jsonapi.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
jsonb.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
logtape.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
lsyscache.h Improve index AMs' opclass validation procedures. 2016-01-21 19:47:15 -05:00
memdebug.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
memutils.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
nabstime.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
numeric.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
palloc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_crc.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_locale.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_lsn.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
pg_rusage.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
plancache.h Only try to push down foreign joins if the user mapping OIDs match. 2016-01-28 14:05:36 -05:00
portal.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
ps_status.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rangetypes.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rel.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
relcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
relfilenodemap.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
relmapper.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
reltrigger.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
resowner.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
resowner_private.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
rls.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
ruleutils.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
sampling.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
selfuncs.h Restructure index access method API to hide most of it at the C level. 2016-01-17 19:36:59 -05:00
snapmgr.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
snapshot.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
sortsupport.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
spccache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
syscache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
timeout.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
timestamp.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tqual.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tuplesort.h Reuse abbreviated keys in ordered [set] aggregates. 2016-02-17 15:40:00 +05:30
tuplestore.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
typcache.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
tzparser.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
uuid.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
varbit.h Update copyright for 2016 2016-01-02 13:33:40 -05:00
xml.h Update copyright for 2016 2016-01-02 13:33:40 -05:00