diff options
| author | Alexander Korotkov | 2024-03-30 20:34:04 +0000 |
|---|---|---|
| committer | Alexander Korotkov | 2024-03-30 20:34:04 +0000 |
| commit | 27bc1772fc814946918a5ac8ccb9b5c5ad0380aa (patch) | |
| tree | beb4fac8dfb2756c86f3ac13ec21d72f69daa55c /src/include/commands | |
| parent | b154d8a6d0e52e5f6b09739639fdf55fa88bc6b8 (diff) | |
Generalize relation analyze in table AM interface
Currently, there is just one algorithm for sampling tuples from a table written
in acquire_sample_rows(). Custom table AM can just redefine the way to get the
next block/tuple by implementing scan_analyze_next_block() and
scan_analyze_next_tuple() API functions.
This approach doesn't seem general enough. For instance, it's unclear how to
sample this way index-organized tables. This commit allows table AM to
encapsulate the whole sampling algorithm (currently implemented in
acquire_sample_rows()) into the relation_analyze() API function.
Discussion: https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com
Reviewed-by: Pavel Borisov, Matthias van de Meent
Diffstat (limited to 'src/include/commands')
| -rw-r--r-- | src/include/commands/vacuum.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index 1182a967427..68068dd9003 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -175,6 +175,21 @@ typedef struct VacAttrStats int rowstride; } VacAttrStats; +/* + * AcquireSampleRowsFunc - a function for the sampling statistics collection. + * + * A random sample of up to `targrows` rows should be collected from the + * table and stored into the caller-provided `rows` array. The actual number + * of rows collected must be returned. In addition, a function should store + * estimates of the total numbers of live and dead rows in the table into the + * output parameters `*totalrows` and `*totaldeadrows1. (Set `*totaldeadrows` + * to zero if the storage does not have any concept of dead rows.) + */ +typedef int (*AcquireSampleRowsFunc) (Relation relation, int elevel, + HeapTuple *rows, int targrows, + double *totalrows, + double *totaldeadrows); + /* flag bits for VacuumParams->options */ #define VACOPT_VACUUM 0x01 /* do VACUUM */ #define VACOPT_ANALYZE 0x02 /* do ANALYZE */ @@ -380,6 +395,10 @@ extern void parallel_vacuum_main(dsm_segment *seg, shm_toc *toc); 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 bool std_typanalyze(VacAttrStats *stats); /* in utils/misc/sampling.c --- duplicate of declarations in utils/sampling.h */ |
