30 #include "utils/fmgrprotos.h"
54 if (attr->attstattarget < 0)
60 stats->
minrows = 300 * attr->attstattarget;
81 if (attr->attstattarget < 0)
87 stats->
minrows = 300 * attr->attstattarget;
127 int samplerows,
double totalrows)
133 int non_null_cnt = 0;
134 int non_empty_cnt = 0;
138 int num_bins = stats->
attr->attstattarget;
143 double total_width = 0;
145 if (typcache->
typtype == TYPTYPE_MULTIRANGE)
147 mltrng_typcache = typcache;
160 for (range_no = 0; range_no < samplerows; range_no++)
173 value = fetchfunc(stats, range_no, &isnull);
188 if (mltrng_typcache != NULL)
217 lowers[non_empty_cnt] =
lower;
218 uppers[non_empty_cnt] =
upper;
225 else if (has_subdiff)
240 lengths[non_empty_cnt] = length;
253 if (non_null_cnt > 0)
255 Datum *bound_hist_values;
256 Datum *length_hist_values;
267 stats->
stanullfrac = (double) null_cnt / (
double) samplerows;
268 stats->
stawidth = total_width / (double) non_null_cnt;
280 if (non_empty_cnt >= 2)
288 num_hist = non_empty_cnt;
289 if (num_hist > num_bins)
290 num_hist = num_bins + 1;
305 delta = (non_empty_cnt - 1) / (num_hist - 1);
306 deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
309 for (
i = 0;
i < num_hist;
i++)
316 posfrac += deltafrac;
317 if (posfrac >= (num_hist - 1))
321 posfrac -= (num_hist - 1);
325 stats->
stakind[slot_idx] = STATISTIC_KIND_BOUNDS_HISTOGRAM;
326 stats->
stavalues[slot_idx] = bound_hist_values;
342 if (non_empty_cnt >= 2)
350 num_hist = non_empty_cnt;
351 if (num_hist > num_bins)
352 num_hist = num_bins + 1;
365 delta = (non_empty_cnt - 1) / (num_hist - 1);
366 deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
369 for (
i = 0;
i < num_hist;
i++)
373 posfrac += deltafrac;
374 if (posfrac >= (num_hist - 1))
378 posfrac -= (num_hist - 1);
390 length_hist_values =
palloc(0);
393 stats->
staop[slot_idx] = Float8LessOperator;
395 stats->
stavalues[slot_idx] = length_hist_values;
397 stats->
statypid[slot_idx] = FLOAT8OID;
404 *emptyfrac = ((double) empty_cnt) / ((double) non_null_cnt);
408 stats->
stakind[slot_idx] = STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM;
413 else if (null_cnt > 0)
#define OidIsValid(objectId)
int default_statistics_target
static float8 get_float8_infinity(void)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Datum Float8GetDatum(float8 X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_BOOL(x)
static const FormData_pg_attribute a1
static const FormData_pg_attribute a2
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
Oid getBaseType(Oid typid)
TypeCacheEntry * multirange_get_typcache(FunctionCallInfo fcinfo, Oid mltrngtypid)
void multirange_get_bounds(TypeCacheEntry *rangetyp, const MultirangeType *multirange, uint32 i, RangeBound *lower, RangeBound *upper)
#define MultirangeIsEmpty(mr)
#define DatumGetMultirangeTypeP(X)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
FormData_pg_attribute * Form_pg_attribute
void qsort_arg(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
#define qsort(a, b, c, d)
#define DatumGetPointer(X)
#define DatumGetFloat8(X)
#define PointerGetDatum(X)
int range_cmp_bounds(TypeCacheEntry *typcache, const RangeBound *b1, const RangeBound *b2)
RangeType * range_serialize(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
void range_deserialize(TypeCacheEntry *typcache, const RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
TypeCacheEntry * range_get_typcache(FunctionCallInfo fcinfo, Oid rngtypid)
#define DatumGetRangeTypeP(X)
static int float8_qsort_cmp(const void *a1, const void *a2)
Datum multirange_typanalyze(PG_FUNCTION_ARGS)
static int range_bound_qsort_cmp(const void *a1, const void *a2, void *arg)
Datum range_typanalyze(PG_FUNCTION_ARGS)
static void compute_range_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, int samplerows, double totalrows)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
struct TypeCacheEntry * rngtype
FmgrInfo rng_subdiff_finfo
int16 stakind[STATISTIC_NUM_SLOTS]
MemoryContext anl_context
Oid statypid[STATISTIC_NUM_SLOTS]
Oid staop[STATISTIC_NUM_SLOTS]
Oid stacoll[STATISTIC_NUM_SLOTS]
char statypalign[STATISTIC_NUM_SLOTS]
float4 * stanumbers[STATISTIC_NUM_SLOTS]
bool statypbyval[STATISTIC_NUM_SLOTS]
int16 statyplen[STATISTIC_NUM_SLOTS]
int numvalues[STATISTIC_NUM_SLOTS]
Datum * stavalues[STATISTIC_NUM_SLOTS]
int numnumbers[STATISTIC_NUM_SLOTS]
AnalyzeAttrComputeStatsFunc compute_stats
void vacuum_delay_point(void)
Datum(* AnalyzeAttrFetchFunc)(VacAttrStatsP stats, int rownum, bool *isNull)