1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-07 19:06:32 +03:00

Take pg_attribute out of VacAttrStats

The VacAttrStats structure contained the whole Form_pg_attribute for a
column, but it actually only needs attstattarget from there.  So
remove the Form_pg_attribute field and make a separate field for
attstattarget.  This simplifies some code for extended statistics that
doesn't deal with a column but an expression, which had to fake up
pg_attribute rows to satisfy internal APIs.  Also, we can remove some
comments that essentially said "don't look at pg_attribute directly".

Reviewed-by: Tomas Vondra <tomas.vondra@enterprisedb.com>
Discussion: https://www.postgresql.org/message-id/flat/d6069765-5971-04d3-c10d-e4f7b2e9c459%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2023-07-03 07:09:22 +02:00
parent 7a7f60aef8
commit c69bdf837f
6 changed files with 43 additions and 80 deletions

View File

@@ -263,7 +263,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
* the number of individual elements tracked in pg_statistic ought to be
* more than the number of values for a simple scalar column.
*/
num_mcelem = stats->attr->attstattarget * 10;
num_mcelem = stats->attstattarget * 10;
/*
* We set bucket width equal to num_mcelem / 0.007 as per the comment
@@ -575,7 +575,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
count_items_count = hash_get_num_entries(count_tab);
if (count_items_count > 0)
{
int num_hist = stats->attr->attstattarget;
int num_hist = stats->attstattarget;
DECountItem **sorted_count_items;
int j;
int delta;

View File

@@ -47,18 +47,17 @@ range_typanalyze(PG_FUNCTION_ARGS)
{
VacAttrStats *stats = (VacAttrStats *) PG_GETARG_POINTER(0);
TypeCacheEntry *typcache;
Form_pg_attribute attr = stats->attr;
/* Get information about range type; note column might be a domain */
typcache = range_get_typcache(fcinfo, getBaseType(stats->attrtypid));
if (attr->attstattarget < 0)
attr->attstattarget = default_statistics_target;
if (stats->attstattarget < 0)
stats->attstattarget = default_statistics_target;
stats->compute_stats = compute_range_stats;
stats->extra_data = typcache;
/* same as in std_typanalyze */
stats->minrows = 300 * attr->attstattarget;
stats->minrows = 300 * stats->attstattarget;
PG_RETURN_BOOL(true);
}
@@ -74,18 +73,17 @@ multirange_typanalyze(PG_FUNCTION_ARGS)
{
VacAttrStats *stats = (VacAttrStats *) PG_GETARG_POINTER(0);
TypeCacheEntry *typcache;
Form_pg_attribute attr = stats->attr;
/* Get information about multirange type; note column might be a domain */
typcache = multirange_get_typcache(fcinfo, getBaseType(stats->attrtypid));
if (attr->attstattarget < 0)
attr->attstattarget = default_statistics_target;
if (stats->attstattarget < 0)
stats->attstattarget = default_statistics_target;
stats->compute_stats = compute_range_stats;
stats->extra_data = typcache;
/* same as in std_typanalyze */
stats->minrows = 300 * attr->attstattarget;
stats->minrows = 300 * stats->attstattarget;
PG_RETURN_BOOL(true);
}
@@ -136,7 +134,7 @@ compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
int empty_cnt = 0;
int range_no;
int slot_idx;
int num_bins = stats->attr->attstattarget;
int num_bins = stats->attstattarget;
int num_hist;
float8 *lengths;
RangeBound *lowers,