30 #include "utils/fmgrprotos.h"
126 int samplerows,
double totalrows)
132 int non_null_cnt = 0;
133 int non_empty_cnt = 0;
142 double total_width = 0;
144 if (typcache->
typtype == TYPTYPE_MULTIRANGE)
146 mltrng_typcache = typcache;
159 for (range_no = 0; range_no < samplerows; range_no++)
172 value = fetchfunc(stats, range_no, &isnull);
187 if (mltrng_typcache != NULL)
216 lowers[non_empty_cnt] =
lower;
217 uppers[non_empty_cnt] =
upper;
224 else if (has_subdiff)
239 lengths[non_empty_cnt] = length;
252 if (non_null_cnt > 0)
254 Datum *bound_hist_values;
255 Datum *length_hist_values;
266 stats->
stanullfrac = (double) null_cnt / (
double) samplerows;
267 stats->
stawidth = total_width / (double) non_null_cnt;
279 if (non_empty_cnt >= 2)
287 num_hist = non_empty_cnt;
288 if (num_hist > num_bins)
289 num_hist = num_bins + 1;
304 delta = (non_empty_cnt - 1) / (num_hist - 1);
305 deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
308 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)
351 num_hist = non_empty_cnt;
352 if (num_hist > num_bins)
353 num_hist = num_bins + 1;
366 delta = (non_empty_cnt - 1) / (num_hist - 1);
367 deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
370 for (
i = 0;
i < num_hist;
i++)
374 posfrac += deltafrac;
375 if (posfrac >= (num_hist - 1))
379 posfrac -= (num_hist - 1);
391 length_hist_values =
palloc(0);
394 stats->
staop[slot_idx] = Float8LessOperator;
396 stats->
stavalues[slot_idx] = length_hist_values;
398 stats->
statypid[slot_idx] = FLOAT8OID;
405 *emptyfrac = ((double) empty_cnt) / ((double) non_null_cnt);
409 stats->
stakind[slot_idx] = STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM;
414 else if (null_cnt > 0)
#define Assert(condition)
#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)
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)
static MultirangeType * DatumGetMultirangeTypeP(Datum X)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
void qsort_interruptible(void *base, size_t nel, size_t elsize, qsort_arg_comparator cmp, void *arg)
static Datum PointerGetDatum(const void *X)
static float8 DatumGetFloat8(Datum X)
static Pointer DatumGetPointer(Datum X)
MemoryContextSwitchTo(old_ctx)
int range_cmp_bounds(TypeCacheEntry *typcache, const RangeBound *b1, const RangeBound *b2)
void range_deserialize(TypeCacheEntry *typcache, const RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
TypeCacheEntry * range_get_typcache(FunctionCallInfo fcinfo, Oid rngtypid)
RangeType * range_serialize(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty, struct Node *escontext)
static RangeType * DatumGetRangeTypeP(Datum X)
Datum multirange_typanalyze(PG_FUNCTION_ARGS)
static int float8_qsort_cmp(const void *a1, const void *a2, void *arg)
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)