• Alvaro Herrera's avatar
    Avoid spurious waits in concurrent indexing · c98763bf
    Alvaro Herrera authored
    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: default avatarMichael Paquier <michael@paquier.xyz>
    Discussion: https://postgr.es/m/20200810233815.GA18970@alvherre.pgsql
    c98763bf
indexcmds.c 120 KB