HI, hackers
So far, I have only found compute_scalar_stats() and
compute_distinct_stats() that
generate STATISTIC_KIND_MCV statistics. The way they allocate space for and
populate
most_common_vals and most_common_freqs, as well as determine their number of
elements,
is the same in both cases. In other words, these two arrays always have the
same number of elements.
The relevant code is briefly shown below:
```C
/* Generate MCV slot entry */
mcv_values = palloc_array(Datum, num_mcv);
mcv_freqs = palloc_array(float4, num_mcv);
for (i = 0; i < num_mcv; i++)
{
mcv_values[i] = datumCopy(values[track[i].first].value,
stats->attrtype->typbyval,
stats->attrtype->typlen);
mcv_freqs[i] = (double) track[i].count / (double)
samplerows;
}
MemoryContextSwitchTo(old_context);
stats->stakind[slot_idx] = STATISTIC_KIND_MCV;
stats->staop[slot_idx] = mystats->eqopr;
stats->stacoll[slot_idx] = stats->attrcollid;
stats->stanumbers[slot_idx] = mcv_freqs;
stats->numnumbers[slot_idx] = num_mcv;
stats->stavalues[slot_idx] = mcv_values;
stats->numvalues[slot_idx] = num_mcv;
regards,
--
ZizhuanLiu (X-MAN)
[email protected]