summaryrefslogtreecommitdiff
path: root/src/backend/statistics/mcv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/statistics/mcv.c')
-rw-r--r--src/backend/statistics/mcv.c108
1 files changed, 55 insertions, 53 deletions
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 3147d8fedc6..6a262f15436 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -210,8 +210,8 @@ statext_mcv_build(int numrows, HeapTuple *rows, Bitmapset *attrs,
groups = build_distinct_groups(nitems, items, mss, &ngroups);
/*
- * Maximum number of MCV items to store, based on the statistics target
- * we computed for the statistics object (from target set for the object
+ * Maximum number of MCV items to store, based on the statistics target we
+ * computed for the statistics object (from target set for the object
* itself, attributes and the system default). In any case, we can't keep
* more groups than we have available.
*/
@@ -261,7 +261,7 @@ statext_mcv_build(int numrows, HeapTuple *rows, Bitmapset *attrs,
{
int j;
SortItem key;
- MultiSortSupport tmp;
+ MultiSortSupport tmp;
/* frequencies for values in each attribute */
SortItem **freqs;
@@ -463,7 +463,7 @@ build_distinct_groups(int numrows, SortItem *items, MultiSortSupport mss,
static int
sort_item_compare(const void *a, const void *b, void *arg)
{
- SortSupport ssup = (SortSupport) arg;
+ SortSupport ssup = (SortSupport) arg;
SortItem *ia = (SortItem *) a;
SortItem *ib = (SortItem *) b;
@@ -499,7 +499,7 @@ build_column_frequencies(SortItem *groups, int ngroups,
/* allocate arrays for all columns as a single chunk */
ptr = palloc(MAXALIGN(sizeof(SortItem *) * mss->ndims) +
- mss->ndims * MAXALIGN(sizeof(SortItem) * ngroups));
+ mss->ndims * MAXALIGN(sizeof(SortItem) * ngroups));
/* initial array of pointers */
result = (SortItem **) ptr;
@@ -507,7 +507,7 @@ build_column_frequencies(SortItem *groups, int ngroups,
for (dim = 0; dim < mss->ndims; dim++)
{
- SortSupport ssup = &mss->ssup[dim];
+ SortSupport ssup = &mss->ssup[dim];
/* array of values for a single column */
result[dim] = (SortItem *) ptr;
@@ -528,15 +528,15 @@ build_column_frequencies(SortItem *groups, int ngroups,
/*
* Identify distinct values, compute frequency (there might be
- * multiple MCV items containing this value, so we need to sum
- * counts from all of them.
+ * multiple MCV items containing this value, so we need to sum counts
+ * from all of them.
*/
ncounts[dim] = 1;
for (i = 1; i < ngroups; i++)
{
- if (sort_item_compare(&result[dim][i-1], &result[dim][i], ssup) == 0)
+ if (sort_item_compare(&result[dim][i - 1], &result[dim][i], ssup) == 0)
{
- result[dim][ncounts[dim]-1].count += result[dim][i].count;
+ result[dim][ncounts[dim] - 1].count += result[dim][i].count;
continue;
}
@@ -723,23 +723,23 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats)
*/
info[dim].nvalues = ndistinct;
- if (info[dim].typbyval) /* by-value data types */
+ if (info[dim].typbyval) /* by-value data types */
{
info[dim].nbytes = info[dim].nvalues * info[dim].typlen;
/*
* We copy the data into the MCV item during deserialization, so
* we don't need to allocate any extra space.
- */
+ */
info[dim].nbytes_aligned = 0;
}
- else if (info[dim].typlen > 0) /* fixed-length by-ref */
+ else if (info[dim].typlen > 0) /* fixed-length by-ref */
{
/*
* We don't care about alignment in the serialized data, so we
* pack the data as much as possible. But we also track how much
- * data will be needed after deserialization, and in that case
- * we need to account for alignment of each item.
+ * data will be needed after deserialization, and in that case we
+ * need to account for alignment of each item.
*
* Note: As the items are fixed-length, we could easily compute
* this during deserialization, but we do it here anyway.
@@ -765,8 +765,8 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats)
/* serialized length (uint32 length + data) */
len = VARSIZE_ANY_EXHDR(values[dim][i]);
- info[dim].nbytes += sizeof(uint32); /* length */
- info[dim].nbytes += len; /* value (no header) */
+ info[dim].nbytes += sizeof(uint32); /* length */
+ info[dim].nbytes += len; /* value (no header) */
/*
* During deserialization we'll build regular varlena values
@@ -792,8 +792,8 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats)
/* c-strings include terminator, so +1 byte */
len = strlen(DatumGetCString(values[dim][i])) + 1;
- info[dim].nbytes += sizeof(uint32); /* length */
- info[dim].nbytes += len; /* value */
+ info[dim].nbytes += sizeof(uint32); /* length */
+ info[dim].nbytes += len; /* value */
/* space needed for properly aligned deserialized copies */
info[dim].nbytes_aligned += MAXALIGN(len);
@@ -809,9 +809,9 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats)
* whole serialized MCV list (varlena header, MCV header, dimension info
* for each attribute, deduplicated values and items).
*/
- total_length = (3 * sizeof(uint32)) /* magic + type + nitems */
- + sizeof(AttrNumber) /* ndimensions */
- + (ndims * sizeof(Oid)); /* attribute types */
+ total_length = (3 * sizeof(uint32)) /* magic + type + nitems */
+ + sizeof(AttrNumber) /* ndimensions */
+ + (ndims * sizeof(Oid)); /* attribute types */
/* dimension info */
total_length += ndims * sizeof(DimensionInfo);
@@ -954,7 +954,8 @@ statext_mcv_serialize(MCVList *mcvlist, VacAttrStats **stats)
info[dim].nvalues, sizeof(Datum),
compare_scalars_simple, &ssup[dim]);
- Assert(value != NULL); /* serialization or deduplication error */
+ Assert(value != NULL); /* serialization or deduplication
+ * error */
/* compute index within the deduplicated array */
index = (uint16) (value - values[dim]);
@@ -1147,8 +1148,8 @@ statext_mcv_deserialize(bytea *data)
* serialized data - it's not aligned properly, and it may disappear while
* we're still using the MCV list, e.g. due to catcache release.
*
- * We do care about alignment here, because we will allocate all the pieces
- * at once, but then use pointers to different parts.
+ * We do care about alignment here, because we will allocate all the
+ * pieces at once, but then use pointers to different parts.
*/
mcvlen = MAXALIGN(offsetof(MCVList, items) + (sizeof(MCVItem) * nitems));
@@ -1291,7 +1292,7 @@ statext_mcv_deserialize(bytea *data)
/* finally translate the indexes (for non-NULL only) */
for (dim = 0; dim < ndims; dim++)
{
- uint16 index;
+ uint16 index;
memcpy(&index, ptr, sizeof(uint16));
ptr += sizeof(uint16);
@@ -1377,7 +1378,8 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS)
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
- if (funcctx->call_cntr < funcctx->max_calls) /* do when there is more left to send */
+ if (funcctx->call_cntr < funcctx->max_calls) /* do when there is more
+ * left to send */
{
Datum values[5];
bool nulls[5];
@@ -1400,10 +1402,10 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS)
{
astate_nulls = accumArrayResult(astate_nulls,
- BoolGetDatum(item->isnull[i]),
- false,
- BOOLOID,
- CurrentMemoryContext);
+ BoolGetDatum(item->isnull[i]),
+ false,
+ BOOLOID,
+ CurrentMemoryContext);
if (!item->isnull[i])
{
@@ -1421,17 +1423,17 @@ pg_stats_ext_mcvlist_items(PG_FUNCTION_ARGS)
txt = cstring_to_text(DatumGetPointer(val));
astate_values = accumArrayResult(astate_values,
- PointerGetDatum(txt),
- false,
- TEXTOID,
- CurrentMemoryContext);
+ PointerGetDatum(txt),
+ false,
+ TEXTOID,
+ CurrentMemoryContext);
}
else
astate_values = accumArrayResult(astate_values,
- (Datum) 0,
- true,
- TEXTOID,
- CurrentMemoryContext);
+ (Datum) 0,
+ true,
+ TEXTOID,
+ CurrentMemoryContext);
}
values[0] = Int32GetDatum(funcctx->call_cntr);
@@ -1606,9 +1608,9 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
MCVItem *item = &mcvlist->items[i];
/*
- * When the MCV item or the Const value is NULL we can treat
- * this as a mismatch. We must not call the operator because
- * of strictness.
+ * When the MCV item or the Const value is NULL we can
+ * treat this as a mismatch. We must not call the operator
+ * because of strictness.
*/
if (item->isnull[idx] || cst->constisnull)
{
@@ -1631,10 +1633,10 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
*
* We don't store collations used to build the statistics,
* but we can use the collation for the attribute itself,
- * as stored in varcollid. We do reset the statistics after
- * a type change (including collation change), so this is
- * OK. We may need to relax this after allowing extended
- * statistics on expressions.
+ * as stored in varcollid. We do reset the statistics
+ * after a type change (including collation change), so
+ * this is OK. We may need to relax this after allowing
+ * extended statistics on expressions.
*/
if (varonleft)
match = DatumGetBool(FunctionCall2Coll(&opproc,
@@ -1654,7 +1656,7 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
}
else if (IsA(clause, ScalarArrayOpExpr))
{
- ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause;
+ ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause;
FmgrInfo opproc;
/* valid only after examine_clause_args returns true */
@@ -1707,9 +1709,9 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
MCVItem *item = &mcvlist->items[i];
/*
- * When the MCV item or the Const value is NULL we can treat
- * this as a mismatch. We must not call the operator because
- * of strictness.
+ * When the MCV item or the Const value is NULL we can
+ * treat this as a mismatch. We must not call the operator
+ * because of strictness.
*/
if (item->isnull[idx] || cst->constisnull)
{
@@ -1727,9 +1729,9 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
for (j = 0; j < num_elems; j++)
{
- Datum elem_value = elem_values[j];
- bool elem_isnull = elem_nulls[j];
- bool elem_match;
+ Datum elem_value = elem_values[j];
+ bool elem_isnull = elem_nulls[j];
+ bool elem_match;
/* NULL values always evaluate as not matching. */
if (elem_isnull)