30 #include "utils/fmgrprotos.h"
55 if (attr->attstattarget < 0)
61 stats->
minrows = 300 * attr->attstattarget;
82 if (attr->attstattarget < 0)
88 stats->
minrows = 300 * attr->attstattarget;
128 int samplerows,
double totalrows)
134 int non_null_cnt = 0;
135 int non_empty_cnt = 0;
139 int num_bins = stats->
attr->attstattarget;
144 double total_width = 0;
146 if (typcache->
typtype == TYPTYPE_MULTIRANGE)
148 mltrng_typcache = typcache;
161 for (range_no = 0; range_no < samplerows; range_no++)
174 value = fetchfunc(stats, range_no, &isnull);
189 if (mltrng_typcache != NULL)
218 lowers[non_empty_cnt] =
lower;
219 uppers[non_empty_cnt] =
upper;
226 else if (has_subdiff)
241 lengths[non_empty_cnt] = length;
254 if (non_null_cnt > 0)
256 Datum *bound_hist_values;
257 Datum *length_hist_values;
268 stats->
stanullfrac = (double) null_cnt / (
double) samplerows;
269 stats->
stawidth = total_width / (double) non_null_cnt;
281 if (non_empty_cnt >= 2)
289 num_hist = non_empty_cnt;
290 if (num_hist > num_bins)
291 num_hist = num_bins + 1;
306 delta = (non_empty_cnt - 1) / (num_hist - 1);
307 deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
310 for (
i = 0;
i < num_hist;
i++)
318 posfrac += deltafrac;
319 if (posfrac >= (num_hist - 1))
323 posfrac -= (num_hist - 1);
327 stats->
stakind[slot_idx] = STATISTIC_KIND_BOUNDS_HISTOGRAM;
328 stats->
stavalues[slot_idx] = bound_hist_values;
344 if (non_empty_cnt >= 2)
353 num_hist = non_empty_cnt;
354 if (num_hist > num_bins)
355 num_hist = num_bins + 1;
368 delta = (non_empty_cnt - 1) / (num_hist - 1);
369 deltafrac = (non_empty_cnt - 1) % (num_hist - 1);
372 for (
i = 0;
i < num_hist;
i++)
376 posfrac += deltafrac;
377 if (posfrac >= (num_hist - 1))
381 posfrac -= (num_hist - 1);
393 length_hist_values =
palloc(0);
396 stats->
staop[slot_idx] = Float8LessOperator;
398 stats->
stavalues[slot_idx] = length_hist_values;
400 stats->
statypid[slot_idx] = FLOAT8OID;
407 *emptyfrac = ((double) empty_cnt) / ((double) non_null_cnt);
411 stats->
stakind[slot_idx] = STATISTIC_KIND_RANGE_LENGTH_HISTOGRAM;
416 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)
static MultirangeType * DatumGetMultirangeTypeP(Datum X)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
FormData_pg_attribute * Form_pg_attribute
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)
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)