Re: Fix var_eq_const: sum selectivity of all matching MCV entries instead of stopping at first match - Mailing list pgsql-hackers

From ZizhuanLiu X-MAN
Subject Re: Fix var_eq_const: sum selectivity of all matching MCV entries instead of stopping at first match
Date
Msg-id tencent_59DEC6387881B60C5ACE09AE6F26CB1AEA07@qq.com
Whole thread
In response to Re: Fix var_eq_const: sum selectivity of all matching MCV entries instead of stopping at first match  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
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) 
44973863@qq.com

pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: pg_control_checkpoint(): add "data_checksum_version" (Pg19)?
Next
From: Fujii Masao
Date:
Subject: Re: pg_control_checkpoint(): add "data_checksum_version" (Pg19)?