Hello,
While working on Antonin Houska's REPACK code[1][2], I had chance to
give a look at vacuumdb.c with the intention of creating a separate
program, pg_repackdb from it, which would share most of the code. This
patch creates vacuuming.c/h with that intent. While there, I noticed
that that code could be modernized a little bit, so I did that.
I think the most important changes are:
- objfilter is declared as an enum but the values are bit-or'ed and
tested for individual bits. We've discussed this coding pattern in
other contexts and stayed away from it, on the grounds that the values
so generated aren't really true values of the enum. I changed it from
an enum to a bits32 with a few #defines for the values we use, the way
we do elsewhere. Also, instead of being passed as a separate argument
to the various functions, I added it to the vacuumingOpts struct.
- Two booleans, analyze_in_stages and analyze_only, are really
determining what "mode" the program runs in -- it's either vacuum, or
one of those two modes. (Antonin came up with the idea of using
"modes", but his patch only adds a new REPACK mode on top of the
existing code without any further changes). I think the code flow is a
little neater by making this change; consider for instance this change:
- /* If we used SKIP_DATABASE_STATS, mop up with ONLY_DATABASE_STATS */
- if (vacopts->skip_database_stats && stage == ANALYZE_NO_STAGE &&
- !vacopts->analyze_only)
- {
+ /* If we used SKIP_DATABASE_STATS, mop up with ONLY_DATABASE_STATS */
+ if (vacopts->mode == MODE_VACUUM && vacopts->skip_database_stats)
+ {
IMO the original is quite unclear.
Overall I'm quite happy with this small patch now, so I intend to push
shortly barring objections. I'm not adding a new commitfest entry, just
adding this new thread to the existing entry for REPACK. I kept the
patch numbering as used in the other thread.
[1] https://postgr.es/m/202507262156.sb455angijk6@alvherre.pgsql
[2] https://commitfest.postgresql.org/patch/5117/
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"El sabio habla porque tiene algo que decir;
el tonto, porque tiene que decir algo" (Platon).