aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-03-08 09:16:44 +0900
committerMichael Paquier <michael@paquier.xyz>2023-03-08 09:16:44 +0900
commitee56048b0ecfee67a76ba8502b91cb5d91b6b03d (patch)
tree18cc2470bf2658235c2fbd34c63fd086196f6ef0
parent99be6feec9717058b9ac9d80f3584e0a9a6e8580 (diff)
downloadpostgresql-ee56048b0ecfee67a76ba8502b91cb5d91b6b03d.tar.gz
postgresql-ee56048b0ecfee67a76ba8502b91cb5d91b6b03d.zip
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
-rw-r--r--src/backend/commands/vacuum.c34
1 files 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);