aboutsummaryrefslogtreecommitdiff
path: root/contrib/intarray/_int_selfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/intarray/_int_selfuncs.c')
-rw-r--r--contrib/intarray/_int_selfuncs.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/contrib/intarray/_int_selfuncs.c b/contrib/intarray/_int_selfuncs.c
index 9b4a22fe341..3d92025ba56 100644
--- a/contrib/intarray/_int_selfuncs.c
+++ b/contrib/intarray/_int_selfuncs.c
@@ -136,11 +136,7 @@ _int_matchsel(PG_FUNCTION_ARGS)
int nmcelems = 0;
float4 minfreq = 0.0;
float4 nullfrac = 0.0;
- Form_pg_statistic stats;
- Datum *values = NULL;
- int nvalues = 0;
- float4 *numbers = NULL;
- int nnumbers = 0;
+ AttStatsSlot sslot;
/*
* If expression is not "variable @@ something" or "something @@ variable"
@@ -193,6 +189,8 @@ _int_matchsel(PG_FUNCTION_ARGS)
*/
if (HeapTupleIsValid(vardata.statsTuple))
{
+ Form_pg_statistic stats;
+
stats = (Form_pg_statistic) GETSTRUCT(vardata.statsTuple);
nullfrac = stats->stanullfrac;
@@ -200,29 +198,30 @@ _int_matchsel(PG_FUNCTION_ARGS)
* For an int4 array, the default array type analyze function will
* collect a Most Common Elements list, which is an array of int4s.
*/
- if (get_attstatsslot(vardata.statsTuple,
- INT4OID, -1,
+ if (get_attstatsslot(&sslot, vardata.statsTuple,
STATISTIC_KIND_MCELEM, InvalidOid,
- NULL,
- &values, &nvalues,
- &numbers, &nnumbers))
+ ATTSTATSSLOT_VALUES | ATTSTATSSLOT_NUMBERS))
{
+ Assert(sslot.valuetype == INT4OID);
+
/*
* There should be three more Numbers than Values, because the
* last three (for intarray) cells are taken for minimal, maximal
* and nulls frequency. Punt if not.
*/
- if (nnumbers == nvalues + 3)
+ if (sslot.nnumbers == sslot.nvalues + 3)
{
/* Grab the lowest frequency. */
- minfreq = numbers[nnumbers - (nnumbers - nvalues)];
+ minfreq = sslot.numbers[sslot.nnumbers - (sslot.nnumbers - sslot.nvalues)];
- mcelems = values;
- mcefreqs = numbers;
- nmcelems = nvalues;
+ mcelems = sslot.values;
+ mcefreqs = sslot.numbers;
+ nmcelems = sslot.nvalues;
}
}
}
+ else
+ memset(&sslot, 0, sizeof(sslot));
/* Process the logical expression in the query, using the stats */
selec = int_query_opr_selec(GETQUERY(query) + query->size - 1,
@@ -231,7 +230,7 @@ _int_matchsel(PG_FUNCTION_ARGS)
/* MCE stats count only non-null rows, so adjust for null rows. */
selec *= (1.0 - nullfrac);
- free_attstatsslot(INT4OID, values, nvalues, numbers, nnumbers);
+ free_attstatsslot(&sslot);
ReleaseVariableStats(vardata);
CLAMP_PROBABILITY(selec);