]> granicus.if.org Git - postgresql/commit
Enable parallel query with SERIALIZABLE isolation.
authorThomas Munro <tmunro@postgresql.org>
Fri, 15 Mar 2019 03:23:46 +0000 (16:23 +1300)
committerThomas Munro <tmunro@postgresql.org>
Fri, 15 Mar 2019 04:47:04 +0000 (17:47 +1300)
commitbb16aba50c9492490a0b57e600a932798f45cd4f
tree36991984cfb9e141b42c4caf5f1056974526f617
parent13e8643bfc29d3c1455c0946281cdfc24758ffb6
Enable parallel query with SERIALIZABLE isolation.

Previously, the SERIALIZABLE isolation level prevented parallel query
from being used.  Allow the two features to be used together by
sharing the leader's SERIALIZABLEXACT with parallel workers.

An extra per-SERIALIZABLEXACT LWLock is introduced to make it safe to
share, and new logic is introduced to coordinate the early release
of the SERIALIZABLEXACT required for the SXACT_FLAG_RO_SAFE
optimization, as follows:

The first backend to observe the SXACT_FLAG_RO_SAFE flag (set by
some other transaction) will 'partially release' the SERIALIZABLEXACT,
meaning that the conflicts and locks it holds are released, but the
SERIALIZABLEXACT itself will remain active because other backends
might still have a pointer to it.

Whenever any backend notices the SXACT_FLAG_RO_SAFE flag, it clears
its own MySerializableXact variable and frees local resources so that
it can skip SSI checks for the rest of the transaction.  In the
special case of the leader process, it transfers the SERIALIZABLEXACT
to a new variable SavedSerializableXact, so that it can be completely
released at the end of the transaction after all workers have exited.

Remove the serializable_okay flag added to CreateParallelContext() by
commit 9da0cc35, because it's now redundant.

Author: Thomas Munro
Reviewed-by: Haribabu Kommi, Robert Haas, Masahiko Sawada, Kevin Grittner
Discussion: https://postgr.es/m/CAEepm=0gXGYhtrVDWOTHS8SQQy_=S9xo+8oCxGLWZAOoeJ=yzQ@mail.gmail.com
19 files changed:
doc/src/sgml/monitoring.sgml
doc/src/sgml/parallel.sgml
src/backend/access/nbtree/nbtsort.c
src/backend/access/transam/parallel.c
src/backend/access/transam/xact.c
src/backend/executor/execParallel.c
src/backend/optimizer/plan/planner.c
src/backend/storage/lmgr/lwlock.c
src/backend/storage/lmgr/predicate.c
src/backend/utils/resowner/resowner.c
src/include/access/parallel.h
src/include/storage/lwlock.h
src/include/storage/predicate.h
src/include/storage/predicate_internals.h
src/test/isolation/expected/serializable-parallel-2.out [new file with mode: 0644]
src/test/isolation/expected/serializable-parallel.out [new file with mode: 0644]
src/test/isolation/isolation_schedule
src/test/isolation/specs/serializable-parallel-2.spec [new file with mode: 0644]
src/test/isolation/specs/serializable-parallel.spec [new file with mode: 0644]