61 if (attr->attstattarget < 0)
66 stats->
minrows = 300 * attr->attstattarget;
146 double total_width = 0;
169 num_mcelem = stats->
attr->attstattarget * 10;
175 bucket_width = (num_mcelem + 10) * 1000 / 7;
182 MemSet(&hash_ctl, 0,
sizeof(hash_ctl));
188 lexemes_tab =
hash_create(
"Analyzed lexemes table",
198 for (vector_no = 0; vector_no < samplerows; vector_no++)
209 value = fetchfunc(stats, vector_no, &isnull);
237 lexemesptr =
STRPTR(vector);
238 curentryptr =
ARRPTR(vector);
239 for (j = 0; j < vector->
size; j++)
249 hash_key.
lexeme = lexemesptr + curentryptr->
pos;
266 item->
delta = b_current - 1;
276 if (lexeme_no % bucket_width == 0)
292 if (null_cnt < samplerows)
294 int nonnull_cnt = samplerows - null_cnt;
304 stats->
stanullfrac = (double) null_cnt / (
double) samplerows;
305 stats->
stawidth = total_width / (double) nonnull_cnt;
318 cutoff_freq = 9 * lexeme_no / bucket_width;
331 sort_table[track_len++] = item;
339 elog(
DEBUG3,
"tsvector_stats: target # mces = %d, bucket width = %d, " 340 "# lexemes = %d, hashtable size = %d, usable entries = %d",
341 num_mcelem, bucket_width, lexeme_no, i, track_len);
348 if (num_mcelem < track_len)
353 minfreq = sort_table[num_mcelem - 1]->
frequency;
356 num_mcelem = track_len;
362 Datum *mcelem_values;
403 for (i = 0; i < num_mcelem; i++)
410 mcelem_freqs[
i] = (double) item->
frequency / (
double) nonnull_cnt;
412 mcelem_freqs[i++] = (double) minfreq / (
double) nonnull_cnt;
413 mcelem_freqs[
i] = (double) maxfreq / (
double) nonnull_cnt;
416 stats->
stakind[0] = STATISTIC_KIND_MCELEM;
417 stats->
staop[0] = TextEqualOperator;
520 return (*t2)->
frequency - (*t1)->frequency;
#define DatumGetUInt32(X)
#define PointerGetDatum(X)
static int lexeme_compare(const void *key1, const void *key2)
Datum * stavalues[STATISTIC_NUM_SLOTS]
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define MemSet(start, val, len)
long hash_get_num_entries(HTAB *hashp)
#define PG_GETARG_POINTER(n)
bool statypbyval[STATISTIC_NUM_SLOTS]
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
char statypalign[STATISTIC_NUM_SLOTS]
void pfree(void *pointer)
text * cstring_to_text_with_len(const char *s, int len)
int numnumbers[STATISTIC_NUM_SLOTS]
static int lexeme_match(const void *key1, const void *key2, Size keysize)
static void compute_tsvector_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, int samplerows, double totalrows)
static void prune_lexemes_hashtable(HTAB *lexemes_tab, int b_current)
FormData_pg_attribute * Form_pg_attribute
#define TSVectorGetDatum(X)
MemoryContext CurrentMemoryContext
#define DatumGetTSVector(X)
Datum ts_typanalyze(PG_FUNCTION_ARGS)
Oid staop[STATISTIC_NUM_SLOTS]
#define PG_RETURN_BOOL(x)
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
int16 stakind[STATISTIC_NUM_SLOTS]
Oid statypid[STATISTIC_NUM_SLOTS]
static uint32 lexeme_hash(const void *key, Size keysize)
#define Assert(condition)
static int trackitem_compare_frequencies_desc(const void *e1, const void *e2)
float4 * stanumbers[STATISTIC_NUM_SLOTS]
Datum hash_any(register const unsigned char *k, register int keylen)
Datum(* AnalyzeAttrFetchFunc)(VacAttrStatsP stats, int rownum, bool *isNull)
void * hash_seq_search(HASH_SEQ_STATUS *status)
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
MemoryContext anl_context
static int trackitem_compare_lexemes(const void *e1, const void *e2)
#define DatumGetPointer(X)
static dshash_hash hash_key(dshash_table *hash_table, const void *key)
int numvalues[STATISTIC_NUM_SLOTS]
int16 statyplen[STATISTIC_NUM_SLOTS]
AnalyzeAttrComputeStatsFunc compute_stats
#define qsort(a, b, c, d)
void vacuum_delay_point(void)
int default_statistics_target