mirror of
https://github.com/postgres/postgres.git
synced 2025-11-25 12:03:53 +03:00
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
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#define PREDICATE_INTERNALS_H
|
||||
|
||||
#include "storage/lock.h"
|
||||
#include "storage/lwlock.h"
|
||||
|
||||
/*
|
||||
* Commit number.
|
||||
@@ -91,6 +92,9 @@ typedef struct SERIALIZABLEXACT
|
||||
SHM_QUEUE finishedLink; /* list link in
|
||||
* FinishedSerializableTransactions */
|
||||
|
||||
LWLock predicateLockListLock; /* protects predicateLocks in parallel
|
||||
* mode */
|
||||
|
||||
/*
|
||||
* for r/o transactions: list of concurrent r/w transactions that we could
|
||||
* potentially have conflicts with, and vice versa for r/w transactions
|
||||
@@ -123,6 +127,12 @@ typedef struct SERIALIZABLEXACT
|
||||
#define SXACT_FLAG_RO_UNSAFE 0x00000100
|
||||
#define SXACT_FLAG_SUMMARY_CONFLICT_IN 0x00000200
|
||||
#define SXACT_FLAG_SUMMARY_CONFLICT_OUT 0x00000400
|
||||
/*
|
||||
* The following flag means the transaction has been partially released
|
||||
* already, but is being preserved because parallel workers might have a
|
||||
* reference to it. It'll be recycled by the leader at end-of-transaction.
|
||||
*/
|
||||
#define SXACT_FLAG_PARTIALLY_RELEASED 0x00000800
|
||||
|
||||
/*
|
||||
* The following types are used to provide an ad hoc list for holding
|
||||
|
||||
Reference in New Issue
Block a user