postgres.git / summary / log / commit / refs

commit    ee56048b0ecfee67a76ba8502b91cb5d91b6b03d
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Wed Mar 08 00:16:44 2023 +0000

    Improve readability of code PROCESS_MAIN in vacuum_rel()
    
    4211fbd has been handling PROCESS_MAIN in vacuum_rel() with an "if/else
    if" structure to avoid an extra level of indentation, but this has been
    found as being rather parse to read.  This commit updates the code so as
    we check for PROCESS_MAIN in a single place and then handle its
    subpaths, FULL or non-FULL vacuums.  Some comments are added to make
    that clearer for the reader.
    
    Reported-by: Melanie Plageman
    Author: Nathan Bossart
    Reviewed-by: Michael Paquier, Melanie Plageman
    Discussion: https://postgr.es/m/20230306194009.5cn6sp3wjotd36nu@liskov


src/backend/commands/vacuum.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 580f9664991..2e12baf8eb4 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -2058,25 +2058,33 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params, bool skip_privs) save_nestlevel = NewGUCNestLevel(); /* - * Do the actual work --- either FULL or "lazy" vacuum + * If PROCESS_MAIN is set (the default), it's time to vacuum the main + * relation. Otherwise, we can skip this part. If processing the TOAST + * table is required (e.g., PROCESS_TOAST is set), we force PROCESS_MAIN + * to be set when we recurse to the TOAST table. */ - if ((params->options & VACOPT_FULL) && - (params->options & VACOPT_PROCESS_MAIN)) + if (params->options & VACOPT_PROCESS_MAIN) { - ClusterParams cluster_params = {0}; + /* + * Do the actual work --- either FULL or "lazy" vacuum + */ + if (params->options & VACOPT_FULL) + { + ClusterParams cluster_params = {0}; - /* close relation before vacuuming, but hold lock until commit */ - relation_close(rel, NoLock); - rel = NULL; + /* close relation before vacuuming, but hold lock until commit */ + relation_close(rel, NoLock); + rel = NULL; - if ((params->options & VACOPT_VERBOSE) != 0) - cluster_params.options |= CLUOPT_VERBOSE; + if ((params->options & VACOPT_VERBOSE) != 0) + cluster_params.options |= CLUOPT_VERBOSE; - /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ - cluster_rel(relid, InvalidOid, &cluster_params); + /* VACUUM FULL is now a variant of CLUSTER; see cluster.c */ + cluster_rel(relid, InvalidOid, &cluster_params); + } + else + table_relation_vacuum(rel, params, vac_strategy); } - else if (params->options & VACOPT_PROCESS_MAIN) - table_relation_vacuum(rel, params, vac_strategy); /* Roll back any GUC changes executed by index functions */ AtEOXact_GUC(false, save_nestlevel); [parent: 99be6feec971]