From a3a5e5b3ff5993a4f1ad8fbe32265ecfa66f3a2c Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Mon, 28 Oct 2024 12:02:19 +0300 Subject: [PATCH 1/2] Move vacuum_ao.c to src/backend/access/appendonly --- src/backend/access/aocs/aocsam_handler.c | 18 ++---------------- src/backend/access/appendonly/Makefile | 2 +- .../appendonly/appendonly_vacuum.c} | 4 +++- .../access/appendonly/appendonlyam_handler.c | 18 ++---------------- src/backend/commands/Makefile | 2 +- src/include/cdb/appendonly_vacuum.h | 10 ++++++++++ src/include/commands/vacuum.h | 4 ---- 7 files changed, 19 insertions(+), 39 deletions(-) rename src/backend/{commands/vacuum_ao.c => access/appendonly/appendonly_vacuum.c} (99%) create mode 100644 src/include/cdb/appendonly_vacuum.h diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c index 00149a8eba3a..d8206da34e8e 100644 --- a/src/backend/access/aocs/aocsam_handler.c +++ b/src/backend/access/aocs/aocsam_handler.c @@ -29,6 +29,7 @@ #include "catalog/pg_attribute_encoding.h" #include "catalog/storage.h" #include "catalog/storage_xlog.h" +#include "cdb/appendonly_vacuum.h" #include "cdb/cdbappendonlyam.h" #include "cdb/cdbaocsam.h" #include "cdb/cdbvars.h" @@ -1397,21 +1398,6 @@ aoco_relation_copy_data(Relation rel, const RelFileNode *newrnode) smgrclose(dstrel); } -static void -aoco_vacuum_rel(Relation onerel, VacuumParams *params, - BufferAccessStrategy bstrategy) -{ - /* - * We VACUUM an AO_COLUMN table through multiple phases. vacuum_rel() - * orchestrates the phases and calls itself again for each phase, so we - * get here for every phase. ao_vacuum_rel() is a wrapper of dedicated - * ao_vacuum_rel_*() functions for the specific phases. - */ - ao_vacuum_rel(onerel, params, bstrategy); - - return; -} - static void aoco_relation_add_columns(Relation rel, List *newvals, List *constraints, TupleDesc oldDesc) { @@ -2811,7 +2797,7 @@ static const TableAmRoutine ao_column_methods = { .relation_copy_for_cluster = aoco_relation_copy_for_cluster, .relation_add_columns = aoco_relation_add_columns, .relation_rewrite_columns = aoco_relation_rewrite_columns, - .relation_vacuum = aoco_vacuum_rel, + .relation_vacuum = ao_vacuum_rel, .scan_analyze_next_block = aoco_scan_analyze_next_block, .scan_analyze_next_tuple = aoco_scan_analyze_next_tuple, .relation_acquire_sample_rows = aoco_acquire_sample_rows, diff --git a/src/backend/access/appendonly/Makefile b/src/backend/access/appendonly/Makefile index 430e397f2fa1..a0ba2927ddf7 100755 --- a/src/backend/access/appendonly/Makefile +++ b/src/backend/access/appendonly/Makefile @@ -15,7 +15,7 @@ OBJS = appendonlyam_handler.o appendonlyam.o aosegfiles.o aomd.o \ appendonlyblockdirectory.o appendonly_visimap.o \ appendonly_visimap_entry.o appendonly_visimap_store.o \ appendonly_compaction.o appendonly_visimap_udf.o \ - appendonly_blkdir_udf.o aomd_filehandler.o + appendonly_blkdir_udf.o aomd_filehandler.o appendonly_vacuum.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/backend/commands/vacuum_ao.c b/src/backend/access/appendonly/appendonly_vacuum.c similarity index 99% rename from src/backend/commands/vacuum_ao.c rename to src/backend/access/appendonly/appendonly_vacuum.c index 96858b1749a2..d860a361c3f4 100644 --- a/src/backend/commands/vacuum_ao.c +++ b/src/backend/access/appendonly/appendonly_vacuum.c @@ -143,6 +143,7 @@ #include "utils/lsyscache.h" #include "utils/pg_rusage.h" #include "cdb/cdbappendonlyblockdirectory.h" +#include "cdb/appendonly_vacuum.h" static void vacuum_appendonly_index(Relation indexRelation, @@ -163,6 +164,7 @@ static void ao_vacuum_rel_recycle_dead_segments(Relation onerel, VacuumParams *p BufferAccessStrategy bstrategy, AOVacuumRelStats *vacrelstats); static AOVacuumRelStats *init_vacrelstats(void); static void cleanup_vacrelstats(AOVacuumRelStats **vacrelstatsp); +static void scan_index(Relation indrel, Relation aorel, int elevel, BufferAccessStrategy vac_strategy); static void ao_vacuum_rel_pre_cleanup(Relation onerel, VacuumParams *params, BufferAccessStrategy bstrategy, AOVacuumRelStats *vacrelstats) @@ -781,7 +783,7 @@ cleanup_vacrelstats(AOVacuumRelStats **vacrelstats) * * We use this when we have no deletions to do. */ -void +static void scan_index(Relation indrel, Relation aorel, int elevel, BufferAccessStrategy vac_strategy) { IndexBulkDeleteResult *stats; diff --git a/src/backend/access/appendonly/appendonlyam_handler.c b/src/backend/access/appendonly/appendonlyam_handler.c index f3b54cb71b51..e5a917e70c4b 100644 --- a/src/backend/access/appendonly/appendonlyam_handler.c +++ b/src/backend/access/appendonly/appendonlyam_handler.c @@ -34,6 +34,7 @@ #include "catalog/pg_type.h" #include "catalog/storage.h" #include "catalog/storage_xlog.h" +#include "cdb/appendonly_vacuum.h" #include "cdb/cdbappendonlyam.h" #include "cdb/cdbvars.h" #include "commands/progress.h" @@ -1161,21 +1162,6 @@ appendonly_relation_copy_data(Relation rel, const RelFileNode *newrnode) smgrclose(dstrel); } -static void -appendonly_vacuum_rel(Relation onerel, VacuumParams *params, - BufferAccessStrategy bstrategy) -{ - /* - * We VACUUM an AO_ROW table through multiple phases. vacuum_rel() - * orchestrates the phases and calls itself again for each phase, so we - * get here for every phase. ao_vacuum_rel() is a wrapper of dedicated - * ao_vacuum_rel_*() functions for the specific phases. - */ - ao_vacuum_rel(onerel, params, bstrategy); - - return; -} - static void appendonly_relation_add_columns(Relation rel, List *newvals, List *constraints, TupleDesc oldDesc) { @@ -2455,7 +2441,7 @@ static const TableAmRoutine ao_row_methods = { .relation_copy_for_cluster = appendonly_relation_copy_for_cluster, .relation_add_columns = appendonly_relation_add_columns, .relation_rewrite_columns = appendonly_relation_rewrite_columns, - .relation_vacuum = appendonly_vacuum_rel, + .relation_vacuum = ao_vacuum_rel, .scan_analyze_next_block = appendonly_scan_analyze_next_block, .scan_analyze_next_tuple = appendonly_scan_analyze_next_tuple, .relation_acquire_sample_rows = appendonly_acquire_sample_rows, diff --git a/src/backend/commands/Makefile b/src/backend/commands/Makefile index 0a2ecb759ca1..28bb6087d10a 100644 --- a/src/backend/commands/Makefile +++ b/src/backend/commands/Makefile @@ -26,6 +26,6 @@ OBJS = amcmds.o aggregatecmds.o alter.o analyze.o async.o cluster.o comment.o \ vacuum.o variable.o view.o OBJS += analyzefuncs.o analyzeutils.o extprotocolcmds.o exttablecmds.o queue.o -OBJS += resgroupcmds.o tablecmds_gp.o vacuum_ao.o +OBJS += resgroupcmds.o tablecmds_gp.o include $(top_srcdir)/src/backend/common.mk diff --git a/src/include/cdb/appendonly_vacuum.h b/src/include/cdb/appendonly_vacuum.h new file mode 100644 index 000000000000..24f59abcd194 --- /dev/null +++ b/src/include/cdb/appendonly_vacuum.h @@ -0,0 +1,10 @@ +#ifndef APPENDONLY_VACUUM_H +#define APPENDONLY_VACUUM_H + +#include +#include +#include + +void ao_vacuum_rel(Relation rel, VacuumParams *params, BufferAccessStrategy bstrategy); + +#endif /* APPENDONLY_VACUUM_H */ diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index f9caf984f45a..14b63267bef1 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -373,10 +373,6 @@ extern int gp_acquire_sample_rows_func(Relation onerel, int elevel, /* in commands/vacuumlazy.c */ extern void lazy_vacuum_rel_heap(Relation onerel, VacuumParams *params, BufferAccessStrategy bstrategy); -extern void scan_index(Relation indrel, Relation aorel, int elevel, BufferAccessStrategy bstrategy); - -/* in commands/vacuum_ao.c */ -extern void ao_vacuum_rel(Relation rel, VacuumParams *params, BufferAccessStrategy bstrategy); extern bool std_typanalyze(VacAttrStats *stats); From 101c67d798a4d752a62e644e03dbb29c43aa11c2 Mon Sep 17 00:00:00 2001 From: Andrey Sokolov Date: Mon, 28 Oct 2024 17:02:32 +0300 Subject: [PATCH 2/2] Move appendonly_vacuum.h --- src/backend/access/aocs/aocsam_handler.c | 2 +- src/backend/access/appendonly/appendonly_vacuum.c | 2 +- .../cdb => backend/access/appendonly}/appendonly_vacuum.h | 0 src/backend/access/appendonly/appendonlyam_handler.c | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename src/{include/cdb => backend/access/appendonly}/appendonly_vacuum.h (100%) diff --git a/src/backend/access/aocs/aocsam_handler.c b/src/backend/access/aocs/aocsam_handler.c index d8206da34e8e..36b0a4523ec2 100644 --- a/src/backend/access/aocs/aocsam_handler.c +++ b/src/backend/access/aocs/aocsam_handler.c @@ -14,6 +14,7 @@ */ #include "postgres.h" +#include "../appendonly/appendonly_vacuum.h" #include "access/aomd.h" #include "access/appendonlywriter.h" #include "access/heapam.h" @@ -29,7 +30,6 @@ #include "catalog/pg_attribute_encoding.h" #include "catalog/storage.h" #include "catalog/storage_xlog.h" -#include "cdb/appendonly_vacuum.h" #include "cdb/cdbappendonlyam.h" #include "cdb/cdbaocsam.h" #include "cdb/cdbvars.h" diff --git a/src/backend/access/appendonly/appendonly_vacuum.c b/src/backend/access/appendonly/appendonly_vacuum.c index d860a361c3f4..626e6b0c685d 100644 --- a/src/backend/access/appendonly/appendonly_vacuum.c +++ b/src/backend/access/appendonly/appendonly_vacuum.c @@ -123,6 +123,7 @@ #include "access/multixact.h" #include "access/visibilitymap.h" #include "access/xact.h" +#include "appendonly_vacuum.h" #include "catalog/pg_appendonly.h" #include "cdb/cdbappendonlyam.h" #include "cdb/cdbtm.h" @@ -143,7 +144,6 @@ #include "utils/lsyscache.h" #include "utils/pg_rusage.h" #include "cdb/cdbappendonlyblockdirectory.h" -#include "cdb/appendonly_vacuum.h" static void vacuum_appendonly_index(Relation indexRelation, diff --git a/src/include/cdb/appendonly_vacuum.h b/src/backend/access/appendonly/appendonly_vacuum.h similarity index 100% rename from src/include/cdb/appendonly_vacuum.h rename to src/backend/access/appendonly/appendonly_vacuum.h diff --git a/src/backend/access/appendonly/appendonlyam_handler.c b/src/backend/access/appendonly/appendonlyam_handler.c index e5a917e70c4b..f6c67099878b 100644 --- a/src/backend/access/appendonly/appendonlyam_handler.c +++ b/src/backend/access/appendonly/appendonlyam_handler.c @@ -24,6 +24,7 @@ #include "access/tsmapi.h" #include "access/tuptoaster.h" #include "access/xact.h" +#include "appendonly_vacuum.h" #include "catalog/aoseg.h" #include "catalog/catalog.h" #include "catalog/heap.h" @@ -34,7 +35,6 @@ #include "catalog/pg_type.h" #include "catalog/storage.h" #include "catalog/storage_xlog.h" -#include "cdb/appendonly_vacuum.h" #include "cdb/cdbappendonlyam.h" #include "cdb/cdbvars.h" #include "commands/progress.h"