diff options
Diffstat (limited to 'src/include/commands/vacuum.h')
-rw-r--r-- | src/include/commands/vacuum.h | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index 9514f8b2fd8..12a03abb75a 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -21,9 +21,11 @@ #include "catalog/pg_class.h" #include "catalog/pg_statistic.h" #include "catalog/pg_type.h" +#include "executor/tuptable.h" #include "parser/parse_node.h" #include "storage/buf.h" #include "storage/lock.h" +#include "storage/read_stream.h" #include "utils/relcache.h" /* @@ -390,12 +392,60 @@ extern void parallel_vacuum_cleanup_all_indexes(ParallelVacuumState *pvs, extern void parallel_vacuum_main(dsm_segment *seg, shm_toc *toc); /* in commands/analyze.c */ + +struct TableScanDescData; + + +/* + * A callback to prepare to analyze block from `stream` of `scan`. The scan + * has been started with table_beginscan_analyze(). + * + * The callback may acquire resources like locks that are held until + * ScanAnalyzeNextTupleFunc returns false. In some cases it could be + * useful to hold a lock until all tuples in a block have been analyzed by + * ScanAnalyzeNextTupleFunc. + * + * The callback can return false if the block is not suitable for + * sampling, e.g. because it's a metapage that could never contain tuples. + * + * This is primarily suited for block-based AMs. It's not clear what a + * good interface for non block-based AMs would be, so there isn't one + * yet and sampling using a custom implementation of acquire_sample_rows + * may be preferred. + */ +typedef bool (*ScanAnalyzeNextBlockFunc) (struct TableScanDescData *scan, + ReadStream *stream); + +/* + * A callback to iterate over tuples in the block selected with + * ScanAnalyzeNextBlockFunc (which needs to have returned true, and + * this routine may not have returned false for the same block before). If + * a tuple that's suitable for sampling is found, true is returned and a + * tuple is stored in `slot`. + * + * *liverows and *deadrows are incremented according to the encountered + * tuples. + * + * Not every AM might have a meaningful concept of dead rows, in which + * case it's OK to not increment *deadrows - but note that that may + * influence autovacuum scheduling (see comment for relation_vacuum + * callback). + */ +typedef bool (*ScanAnalyzeNextTupleFunc) (struct TableScanDescData *scan, + TransactionId OldestXmin, + double *liverows, + double *deadrows, + TupleTableSlot *slot); + extern void analyze_rel(Oid relid, RangeVar *relation, VacuumParams *params, List *va_cols, bool in_outer_xact, BufferAccessStrategy bstrategy); -extern void heapam_analyze(Relation relation, AcquireSampleRowsFunc *func, - BlockNumber *totalpages, - BufferAccessStrategy bstrategy); +extern void block_level_table_analyze(Relation relation, + AcquireSampleRowsFunc *func, + BlockNumber *totalpages, + BufferAccessStrategy bstrategy, + ScanAnalyzeNextBlockFunc scan_analyze_next_block_cb, + ScanAnalyzeNextTupleFunc scan_analyze_next_tuple_cb); extern bool std_typanalyze(VacAttrStats *stats); |