62 if (attr->attstattarget < 0)
67 stats->
minrows = 300 * attr->attstattarget;
147 double total_width = 0;
170 num_mcelem = stats->
attr->attstattarget * 10;
176 bucket_width = (num_mcelem + 10) * 1000 / 7;
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;
418 stats->
stacoll[0] = DEFAULT_COLLATION_OID;
521 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)
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)
Oid stacoll[STATISTIC_NUM_SLOTS]
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)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
static void prune_lexemes_hashtable(HTAB *lexemes_tab, int b_current)
FormData_pg_attribute * Form_pg_attribute
#define TSVectorGetDatum(X)
MemoryContext CurrentMemoryContext
static Datum hash_any(const unsigned char *k, int keylen)
#define DatumGetTSVector(X)
Datum ts_typanalyze(PG_FUNCTION_ARGS)
Oid staop[STATISTIC_NUM_SLOTS]
#define PG_RETURN_BOOL(x)
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(* 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