mirror of
https://github.com/postgres/postgres.git
synced 2025-11-26 23:43:30 +03:00
Avoid spurious waits in concurrent indexing
In the various waiting phases of CREATE INDEX CONCURRENTLY (CIC) and REINDEX CONCURRENTLY (RC), we wait for other processes to release their snapshots; this is necessary in general for correctness. However, processes doing CIC in other tables cannot possibly affect CIC or RC done in "this" table, so we don't need to wait for those. This commit adds a flag in MyProc->statusFlags to indicate that the current process is doing CIC, so that other processes doing CIC or RC can ignore it when waiting. Note that this logic is only valid if the index does not access other tables. For simplicity we avoid setting the flag if the index has a column that's an expression, or has a WHERE predicate. (It is possible to have expressional or partial indexes that do not access other tables, but figuring that out would require more work.) This flag can potentially also be used by processes doing REINDEX CONCURRENTLY to be skipped; and by VACUUM to ignore processes in CIC or RC for the purposes of computing an Xmin. That's left for future commits. Author: Álvaro Herrera <alvherre@alvh.no-ip.org> Author: Dimitry Dolgov <9erthalion6@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/20200810233815.GA18970@alvherre.pgsql
This commit is contained in:
@@ -53,13 +53,16 @@ struct XidCache
|
||||
*/
|
||||
#define PROC_IS_AUTOVACUUM 0x01 /* is it an autovac worker? */
|
||||
#define PROC_IN_VACUUM 0x02 /* currently running lazy vacuum */
|
||||
#define PROC_IN_SAFE_IC 0x04 /* currently running CREATE INDEX
|
||||
* CONCURRENTLY on non-expressional,
|
||||
* non-partial index */
|
||||
#define PROC_VACUUM_FOR_WRAPAROUND 0x08 /* set by autovac only */
|
||||
#define PROC_IN_LOGICAL_DECODING 0x10 /* currently doing logical
|
||||
* decoding outside xact */
|
||||
|
||||
/* flags reset at EOXact */
|
||||
#define PROC_VACUUM_STATE_MASK \
|
||||
(PROC_IN_VACUUM | PROC_VACUUM_FOR_WRAPAROUND)
|
||||
(PROC_IN_VACUUM | PROC_IN_SAFE_IC | PROC_VACUUM_FOR_WRAPAROUND)
|
||||
|
||||
/*
|
||||
* We allow a small number of "weak" relation locks (AccessShareLock,
|
||||
|
||||
Reference in New Issue
Block a user