diff options
Diffstat (limited to 'src/backend/utils')
31 files changed, 607 insertions, 578 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index d2b23d05cbd..fecf605541a 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -5277,12 +5277,12 @@ check_rolespec_name(const Node *node, const char *detail_msg) ereport(ERROR, (errcode(ERRCODE_RESERVED_NAME), errmsg("role \"%s\" is reserved", - role->rolename), + role->rolename), errdetail("%s", detail_msg))); else ereport(ERROR, (errcode(ERRCODE_RESERVED_NAME), errmsg("role \"%s\" is reserved", - role->rolename))); + role->rolename))); } } diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c index 803ba4752e9..c6c296b9609 100644 --- a/src/backend/utils/adt/datum.c +++ b/src/backend/utils/adt/datum.c @@ -257,7 +257,7 @@ datumIsEqual(Datum value1, Datum value2, bool typByVal, int typLen) Size datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen) { - Size sz = sizeof(int); + Size sz = sizeof(int); if (!isnull) { @@ -267,6 +267,7 @@ datumEstimateSpace(Datum value, bool isnull, bool typByVal, int typLen) else if (VARATT_IS_EXTERNAL_EXPANDED(value)) { ExpandedObjectHeader *eoh = DatumGetEOHP(value); + sz += EOH_get_flat_size(eoh); } else @@ -298,7 +299,7 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, char **start_address) { ExpandedObjectHeader *eoh = NULL; - int header; + int header; /* Write header word. */ if (isnull) @@ -346,8 +347,8 @@ datumSerialize(Datum value, bool isnull, bool typByVal, int typLen, Datum datumRestore(char **start_address, bool *isnull) { - int header; - void *d; + int header; + void *d; /* Read header word. */ memcpy(&header, *start_address, sizeof(int)); diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index d622e98f30a..ae93fe01679 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -5074,9 +5074,9 @@ numeric_to_number(PG_FUNCTION_ARGS) { Numeric x; Numeric a = DatumGetNumeric(DirectFunctionCall1(int4_numeric, - Int32GetDatum(10))); + Int32GetDatum(10))); Numeric b = DatumGetNumeric(DirectFunctionCall1(int4_numeric, - Int32GetDatum(-Num.multi))); + Int32GetDatum(-Num.multi))); x = DatumGetNumeric(DirectFunctionCall2(numeric_power, NumericGetDatum(a), diff --git a/src/backend/utils/adt/geo_spgist.c b/src/backend/utils/adt/geo_spgist.c index e3945f20810..019015656fc 100644 --- a/src/backend/utils/adt/geo_spgist.c +++ b/src/backend/utils/adt/geo_spgist.c @@ -101,19 +101,19 @@ typedef struct { double low; double high; -} Range; +} Range; typedef struct { Range left; Range right; -} RangeBox; +} RangeBox; typedef struct { RangeBox range_box_x; RangeBox range_box_y; -} RectBox; +} RectBox; /* * Calculate the quadrant @@ -173,7 +173,7 @@ getRangeBox(BOX *box) static RectBox * initRectBox(void) { - RectBox *rect_box = (RectBox *) palloc(sizeof(RectBox)); + RectBox *rect_box = (RectBox *) palloc(sizeof(RectBox)); double infinity = get_float8_infinity(); rect_box->range_box_x.left.low = -infinity; @@ -201,7 +201,7 @@ initRectBox(void) static RectBox * nextRectBox(RectBox *rect_box, RangeBox *centroid, uint8 quadrant) { - RectBox *next_rect_box = (RectBox *) palloc(sizeof(RectBox)); + RectBox *next_rect_box = (RectBox *) palloc(sizeof(RectBox)); memcpy(next_rect_box, rect_box, sizeof(RectBox)); @@ -233,7 +233,7 @@ static bool overlap2D(RangeBox *range_box, Range *query) { return FPge(range_box->right.high, query->low) && - FPle(range_box->left.low, query->high); + FPle(range_box->left.low, query->high); } /* Can any rectangle from rect_box overlap with this argument? */ @@ -241,7 +241,7 @@ static bool overlap4D(RectBox *rect_box, RangeBox *query) { return overlap2D(&rect_box->range_box_x, &query->left) && - overlap2D(&rect_box->range_box_y, &query->right); + overlap2D(&rect_box->range_box_y, &query->right); } /* Can any range from range_box contain this argument? */ @@ -249,15 +249,15 @@ static bool contain2D(RangeBox *range_box, Range *query) { return FPge(range_box->right.high, query->high) && - FPle(range_box->left.low, query->low); + FPle(range_box->left.low, query->low); } /* Can any rectangle from rect_box contain this argument? */ static bool -contain4D(RectBox *rect_box, RangeBox * query) +contain4D(RectBox *rect_box, RangeBox *query) { return contain2D(&rect_box->range_box_x, &query->left) && - contain2D(&rect_box->range_box_y, &query->right); + contain2D(&rect_box->range_box_y, &query->right); } /* Can any range from range_box be contained by this argument? */ @@ -265,9 +265,9 @@ static bool contained2D(RangeBox *range_box, Range *query) { return FPle(range_box->left.low, query->high) && - FPge(range_box->left.high, query->low) && - FPle(range_box->right.low, query->high) && - FPge(range_box->right.high, query->low); + FPge(range_box->left.high, query->low) && + FPle(range_box->right.low, query->high) && + FPge(range_box->right.high, query->low); } /* Can any rectangle from rect_box be contained by this argument? */ @@ -275,7 +275,7 @@ static bool contained4D(RectBox *rect_box, RangeBox *query) { return contained2D(&rect_box->range_box_x, &query->left) && - contained2D(&rect_box->range_box_y, &query->right); + contained2D(&rect_box->range_box_y, &query->right); } /* Can any range from range_box to be lower than this argument? */ @@ -283,7 +283,7 @@ static bool lower2D(RangeBox *range_box, Range *query) { return FPlt(range_box->left.low, query->low) && - FPlt(range_box->right.low, query->low); + FPlt(range_box->right.low, query->low); } /* Can any range from range_box to be higher than this argument? */ @@ -291,7 +291,7 @@ static bool higher2D(RangeBox *range_box, Range *query) { return FPgt(range_box->left.high, query->high) && - FPgt(range_box->right.high, query->high); + FPgt(range_box->right.high, query->high); } /* Can any rectangle from rect_box be left of this argument? */ @@ -396,8 +396,8 @@ spg_box_quad_choose(PG_FUNCTION_ARGS) Datum spg_box_quad_picksplit(PG_FUNCTION_ARGS) { - spgPickSplitIn *in = (spgPickSplitIn *) PG_GETARG_POINTER(0); - spgPickSplitOut *out = (spgPickSplitOut *) PG_GETARG_POINTER(1); + spgPickSplitIn *in = (spgPickSplitIn *) PG_GETARG_POINTER(0); + spgPickSplitOut *out = (spgPickSplitOut *) PG_GETARG_POINTER(1); BOX *centroid; int median, i; @@ -409,7 +409,7 @@ spg_box_quad_picksplit(PG_FUNCTION_ARGS) /* Calculate median of all 4D coordinates */ for (i = 0; i < in->nTuples; i++) { - BOX *box = DatumGetBoxP(in->datums[i]); + BOX *box = DatumGetBoxP(in->datums[i]); lowXs[i] = box->low.x; highXs[i] = box->high.x; @@ -442,13 +442,13 @@ spg_box_quad_picksplit(PG_FUNCTION_ARGS) out->leafTupleDatums = palloc(sizeof(Datum) * in->nTuples); /* - * Assign ranges to corresponding nodes according to quadrants - * relative to the "centroid" range + * Assign ranges to corresponding nodes according to quadrants relative to + * the "centroid" range */ for (i = 0; i < in->nTuples; i++) { - BOX *box = DatumGetBoxP(in->datums[i]); - uint8 quadrant = getQuadrant(centroid, box); + BOX *box = DatumGetBoxP(in->datums[i]); + uint8 quadrant = getQuadrant(centroid, box); out->leafTupleDatums[i] = BoxPGetDatum(box); out->mapTuplesToNodes[i] = quadrant; @@ -465,12 +465,12 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS) { spgInnerConsistentIn *in = (spgInnerConsistentIn *) PG_GETARG_POINTER(0); spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1); - int i; - MemoryContext old_ctx; - RectBox *rect_box; - uint8 quadrant; - RangeBox *centroid, - **queries; + int i; + MemoryContext old_ctx; + RectBox *rect_box; + uint8 quadrant; + RangeBox *centroid, + **queries; if (in->allTheSame) { @@ -484,8 +484,8 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS) } /* - * We are saving the traversal value or initialize it an unbounded - * one, if we have just begun to walk the tree. + * We are saving the traversal value or initialize it an unbounded one, if + * we have just begun to walk the tree. */ if (in->traversalValue) rect_box = in->traversalValue; @@ -493,8 +493,8 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS) rect_box = initRectBox(); /* - * We are casting the prefix and queries to RangeBoxes for ease of - * the following operations. + * We are casting the prefix and queries to RangeBoxes for ease of the + * following operations. */ centroid = getRangeBox(DatumGetBoxP(in->prefixDatum)); queries = (RangeBox **) palloc(in->nkeys * sizeof(RangeBox *)); @@ -507,15 +507,15 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS) out->traversalValues = (void **) palloc(sizeof(void *) * in->nNodes); /* - * We switch memory context, because we want to allocate memory for - * new traversal values (next_rect_box) and pass these pieces of - * memory to further call of this function. + * We switch memory context, because we want to allocate memory for new + * traversal values (next_rect_box) and pass these pieces of memory to + * further call of this function. */ old_ctx = MemoryContextSwitchTo(in->traversalMemoryContext); for (quadrant = 0; quadrant < in->nNodes; quadrant++) { - RectBox *next_rect_box = nextRectBox(rect_box, centroid, quadrant); + RectBox *next_rect_box = nextRectBox(rect_box, centroid, quadrant); bool flag = true; for (i = 0; i < in->nkeys; i++) @@ -587,8 +587,8 @@ spg_box_quad_inner_consistent(PG_FUNCTION_ARGS) else { /* - * If this node is not selected, we don't need to keep - * the next traversal value in the memory context. + * If this node is not selected, we don't need to keep the next + * traversal value in the memory context. */ pfree(next_rect_box); } diff --git a/src/backend/utils/adt/jsonb_util.c b/src/backend/utils/adt/jsonb_util.c index e1ceea6da48..ddc34ceec7a 100644 --- a/src/backend/utils/adt/jsonb_util.c +++ b/src/backend/utils/adt/jsonb_util.c @@ -1305,7 +1305,7 @@ compareJsonbScalarValue(JsonbValue *aScalar, JsonbValue *bScalar) case jbvBool: if (aScalar->val.boolean == bScalar->val.boolean) return 0; - else if (aScalar->val.boolean >bScalar->val.boolean) + else if (aScalar->val.boolean > bScalar->val.boolean) return 1; else return -1; diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index fb149dcd477..cb14993542d 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -609,7 +609,7 @@ jsonb_array_element(PG_FUNCTION_ARGS) /* Handle negative subscript */ if (element < 0) { - uint32 nelements = JB_ROOT_COUNT(jb); + uint32 nelements = JB_ROOT_COUNT(jb); if (-element > nelements) PG_RETURN_NULL(); @@ -652,7 +652,7 @@ jsonb_array_element_text(PG_FUNCTION_ARGS) /* Handle negative subscript */ if (element < 0) { - uint32 nelements = JB_ROOT_COUNT(jb); + uint32 nelements = JB_ROOT_COUNT(jb); if (-element > nelements) PG_RETURN_NULL(); @@ -992,7 +992,7 @@ get_array_start(void *state) _state->path_indexes[lex_level] != INT_MIN) { /* Negative subscript -- convert to positive-wise subscript */ - int nelements = json_count_array_elements(_state->lex); + int nelements = json_count_array_elements(_state->lex); if (-_state->path_indexes[lex_level] <= nelements) _state->path_indexes[lex_level] += nelements; @@ -1002,8 +1002,8 @@ get_array_start(void *state) { /* * Special case: we should match the entire array. We only need this - * at the outermost level because at nested levels the match will - * have been started by the outer field or array element callback. + * at the outermost level because at nested levels the match will have + * been started by the outer field or array element callback. */ _state->result_start = _state->lex->token_start; } @@ -3368,9 +3368,9 @@ jsonb_concat(PG_FUNCTION_ARGS) *it2; /* - * If one of the jsonb is empty, just return the other if it's not - * scalar and both are of the same kind. If it's a scalar or they are - * of different kinds we need to perform the concatenation even if one is + * If one of the jsonb is empty, just return the other if it's not scalar + * and both are of the same kind. If it's a scalar or they are of + * different kinds we need to perform the concatenation even if one is * empty. */ if (JB_ROOT_IS_OBJECT(jb1) == JB_ROOT_IS_OBJECT(jb2)) @@ -3481,7 +3481,7 @@ jsonb_delete_idx(PG_FUNCTION_ARGS) it = JsonbIteratorInit(&in->root); r = JsonbIteratorNext(&it, &v, false); - Assert (r == WJB_BEGIN_ARRAY); + Assert(r == WJB_BEGIN_ARRAY); n = v.val.array.nElems; if (idx < 0) @@ -3868,8 +3868,8 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls, if (level == path_len - 1) { /* - * called from jsonb_insert(), it forbids redefining - * an existsing value + * called from jsonb_insert(), it forbids redefining an + * existsing value */ if (op_type & (JB_PATH_INSERT_BEFORE | JB_PATH_INSERT_AFTER)) ereport(ERROR, @@ -3878,7 +3878,7 @@ setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls, errhint("Try using the function jsonb_set " "to replace key value."))); - r = JsonbIteratorNext(it, &v, true); /* skip value */ + r = JsonbIteratorNext(it, &v, true); /* skip value */ if (!(op_type & JB_PATH_DELETE)) { (void) pushJsonbValue(st, WJB_KEY, &k); @@ -4005,8 +4005,8 @@ setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls, /* * We should keep current value only in case of - * JB_PATH_INSERT_BEFORE or JB_PATH_INSERT_AFTER - * because otherwise it should be deleted or replaced + * JB_PATH_INSERT_BEFORE or JB_PATH_INSERT_AFTER because + * otherwise it should be deleted or replaced */ if (op_type & (JB_PATH_INSERT_AFTER | JB_PATH_INSERT_BEFORE)) (void) pushJsonbValue(st, r, &v); diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 39f43863d62..10133f21fac 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -849,13 +849,13 @@ parse_ident(PG_FUNCTION_ARGS) (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("string is not a valid identifier: \"%s\"", text_to_cstring(qualname)), - errdetail("No valid identifier before \".\"."))); + errdetail("No valid identifier before \".\"."))); else if (after_dot) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("string is not a valid identifier: \"%s\"", text_to_cstring(qualname)), - errdetail("No valid identifier after \".\"."))); + errdetail("No valid identifier after \".\"."))); else ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c index 3d21e33a26b..6592ef4d2d9 100644 --- a/src/backend/utils/adt/numeric.c +++ b/src/backend/utils/adt/numeric.c @@ -3355,10 +3355,10 @@ numeric_accum(PG_FUNCTION_ARGS) Datum numeric_combine(PG_FUNCTION_ARGS) { - NumericAggState *state1; - NumericAggState *state2; - MemoryContext agg_context; - MemoryContext old_context; + NumericAggState *state1; + NumericAggState *state2; + MemoryContext agg_context; + MemoryContext old_context; if (!AggCheckCallContext(fcinfo, &agg_context)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -3397,8 +3397,8 @@ numeric_combine(PG_FUNCTION_ARGS) state1->NaNcount += state2->NaNcount; /* - * These are currently only needed for moving aggregates, but let's - * do the right thing anyway... + * These are currently only needed for moving aggregates, but let's do + * the right thing anyway... */ if (state2->maxScale > state1->maxScale) { @@ -3446,10 +3446,10 @@ numeric_avg_accum(PG_FUNCTION_ARGS) Datum numeric_avg_combine(PG_FUNCTION_ARGS) { - NumericAggState *state1; - NumericAggState *state2; - MemoryContext agg_context; - MemoryContext old_context; + NumericAggState *state1; + NumericAggState *state2; + MemoryContext agg_context; + MemoryContext old_context; if (!AggCheckCallContext(fcinfo, &agg_context)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -3485,8 +3485,8 @@ numeric_avg_combine(PG_FUNCTION_ARGS) state1->NaNcount += state2->NaNcount; /* - * These are currently only needed for moving aggregates, but let's - * do the right thing anyway... + * These are currently only needed for moving aggregates, but let's do + * the right thing anyway... */ if (state2->maxScale > state1->maxScale) { @@ -3518,11 +3518,11 @@ numeric_avg_combine(PG_FUNCTION_ARGS) Datum numeric_avg_serialize(PG_FUNCTION_ARGS) { - NumericAggState *state; - StringInfoData buf; - Datum temp; - bytea *sumX; - bytea *result; + NumericAggState *state; + StringInfoData buf; + Datum temp; + bytea *sumX; + bytea *result; /* Ensure we disallow calling when not in aggregate context */ if (!AggCheckCallContext(fcinfo, NULL)) @@ -3549,7 +3549,7 @@ numeric_avg_serialize(PG_FUNCTION_ARGS) pq_sendbytes(&buf, VARDATA(sumX), VARSIZE(sumX) - VARHDRSZ); /* maxScale */ - pq_sendint(&buf, state->maxScale, 4); + pq_sendint(&buf, state->maxScale, 4); /* maxScaleCount */ pq_sendint64(&buf, state->maxScaleCount); @@ -3564,7 +3564,7 @@ numeric_avg_serialize(PG_FUNCTION_ARGS) /* * numeric_avg_deserialize - * Deserialize bytea into NumericAggState for numeric aggregates that + * Deserialize bytea into NumericAggState for numeric aggregates that * don't require sumX2. Deserializes bytea into NumericAggState using the * standard pq API. * @@ -3574,10 +3574,10 @@ numeric_avg_serialize(PG_FUNCTION_ARGS) Datum numeric_avg_deserialize(PG_FUNCTION_ARGS) { - bytea *sstate = PG_GETARG_BYTEA_P(0); - NumericAggState *result; - Datum temp; - StringInfoData buf; + bytea *sstate = PG_GETARG_BYTEA_P(0); + NumericAggState *result; + Datum temp; + StringInfoData buf; if (!AggCheckCallContext(fcinfo, NULL)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -3628,12 +3628,12 @@ numeric_avg_deserialize(PG_FUNCTION_ARGS) Datum numeric_serialize(PG_FUNCTION_ARGS) { - NumericAggState *state; - StringInfoData buf; - Datum temp; - bytea *sumX; - bytea *sumX2; - bytea *result; + NumericAggState *state; + StringInfoData buf; + Datum temp; + bytea *sumX; + bytea *sumX2; + bytea *result; /* Ensure we disallow calling when not in aggregate context */ if (!AggCheckCallContext(fcinfo, NULL)) @@ -3667,7 +3667,7 @@ numeric_serialize(PG_FUNCTION_ARGS) pq_sendbytes(&buf, VARDATA(sumX2), VARSIZE(sumX2) - VARHDRSZ); /* maxScale */ - pq_sendint(&buf, state->maxScale, 4); + pq_sendint(&buf, state->maxScale, 4); /* maxScaleCount */ pq_sendint64(&buf, state->maxScaleCount); @@ -3692,10 +3692,10 @@ numeric_serialize(PG_FUNCTION_ARGS) Datum numeric_deserialize(PG_FUNCTION_ARGS) { - bytea *sstate = PG_GETARG_BYTEA_P(0); - NumericAggState *result; - Datum temp; - StringInfoData buf; + bytea *sstate = PG_GETARG_BYTEA_P(0); + NumericAggState *result; + Datum temp; + StringInfoData buf; if (!AggCheckCallContext(fcinfo, NULL)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -3932,8 +3932,8 @@ numeric_poly_combine(PG_FUNCTION_ARGS) { PolyNumAggState *state1; PolyNumAggState *state2; - MemoryContext agg_context; - MemoryContext old_context; + MemoryContext agg_context; + MemoryContext old_context; if (!AggCheckCallContext(fcinfo, &agg_context)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -4001,11 +4001,11 @@ numeric_poly_combine(PG_FUNCTION_ARGS) Datum numeric_poly_serialize(PG_FUNCTION_ARGS) { - PolyNumAggState *state; - StringInfoData buf; - bytea *sumX; - bytea *sumX2; - bytea *result; + PolyNumAggState *state; + StringInfoData buf; + bytea *sumX; + bytea *sumX2; + bytea *result; /* Ensure we disallow calling when not in aggregate context */ if (!AggCheckCallContext(fcinfo, NULL)) @@ -4040,11 +4040,11 @@ numeric_poly_serialize(PG_FUNCTION_ARGS) free_var(&num); #else temp = DirectFunctionCall1(numeric_send, - NumericGetDatum(make_result(&state->sumX))); + NumericGetDatum(make_result(&state->sumX))); sumX = DatumGetByteaP(temp); temp = DirectFunctionCall1(numeric_send, - NumericGetDatum(make_result(&state->sumX2))); + NumericGetDatum(make_result(&state->sumX2))); sumX2 = DatumGetByteaP(temp); #endif } @@ -4076,11 +4076,11 @@ numeric_poly_serialize(PG_FUNCTION_ARGS) Datum numeric_poly_deserialize(PG_FUNCTION_ARGS) { - bytea *sstate = PG_GETARG_BYTEA_P(0); - PolyNumAggState *result; - Datum sumX; - Datum sumX2; - StringInfoData buf; + bytea *sstate = PG_GETARG_BYTEA_P(0); + PolyNumAggState *result; + Datum sumX; + Datum sumX2; + StringInfoData buf; if (!AggCheckCallContext(fcinfo, NULL)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -4105,13 +4105,13 @@ numeric_poly_deserialize(PG_FUNCTION_ARGS) /* sumX2 */ sumX2 = DirectFunctionCall3(numeric_recv, - PointerGetDatum(&buf), - InvalidOid, - -1); + PointerGetDatum(&buf), + InvalidOid, + -1); #ifdef HAVE_INT128 { - NumericVar num; + NumericVar num; init_var(&num); set_var_from_num(DatumGetNumeric(sumX), &num); @@ -4170,10 +4170,10 @@ int8_avg_accum(PG_FUNCTION_ARGS) Datum int8_avg_combine(PG_FUNCTION_ARGS) { - PolyNumAggState *state1; - PolyNumAggState *state2; - MemoryContext agg_context; - MemoryContext old_context; + PolyNumAggState *state1; + PolyNumAggState *state2; + MemoryContext agg_context; + MemoryContext old_context; if (!AggCheckCallContext(fcinfo, &agg_context)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -4233,10 +4233,10 @@ int8_avg_combine(PG_FUNCTION_ARGS) Datum int8_avg_serialize(PG_FUNCTION_ARGS) { - PolyNumAggState *state; - StringInfoData buf; - bytea *sumX; - bytea *result; + PolyNumAggState *state; + StringInfoData buf; + bytea *sumX; + bytea *result; /* Ensure we disallow calling when not in aggregate context */ if (!AggCheckCallContext(fcinfo, NULL)) @@ -4265,7 +4265,7 @@ int8_avg_serialize(PG_FUNCTION_ARGS) sumX = DatumGetByteaP(temp); #else temp = DirectFunctionCall1(numeric_send, - NumericGetDatum(make_result(&state->sumX))); + NumericGetDatum(make_result(&state->sumX))); sumX = DatumGetByteaP(temp); #endif } @@ -4293,10 +4293,10 @@ int8_avg_serialize(PG_FUNCTION_ARGS) Datum int8_avg_deserialize(PG_FUNCTION_ARGS) { - bytea *sstate = PG_GETARG_BYTEA_P(0); - PolyNumAggState *result; - StringInfoData buf; - Datum temp; + bytea *sstate = PG_GETARG_BYTEA_P(0); + PolyNumAggState *result; + StringInfoData buf; + Datum temp; if (!AggCheckCallContext(fcinfo, NULL)) elog(ERROR, "aggregate function called in non-aggregate context"); @@ -4321,7 +4321,7 @@ int8_avg_deserialize(PG_FUNCTION_ARGS) #ifdef HAVE_INT128 { - NumericVar num; + NumericVar num; init_var(&num); set_var_from_num(DatumGetNumeric(temp), &num); diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 17c5cb0fb64..1bba5fa8c81 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -27,7 +27,7 @@ #include "utils/inet.h" #include "utils/timestamp.h" -#define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) +#define UINT32_ACCESS_ONCE(var) ((uint32)(*((volatile uint32 *)&(var)))) /* bogus ... these externs should be in a header file */ extern Datum pg_stat_get_numscans(PG_FUNCTION_ARGS); @@ -540,7 +540,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS) int num_backends = pgstat_fetch_stat_numbackends(); int curr_backend; char *cmd = text_to_cstring(PG_GETARG_TEXT_PP(0)); - ProgressCommandType cmdtype; + ProgressCommandType cmdtype; TupleDesc tupdesc; Tuplestorestate *tupstore; ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; @@ -582,8 +582,8 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS) /* 1-based index */ for (curr_backend = 1; curr_backend <= num_backends; curr_backend++) { - LocalPgBackendStatus *local_beentry; - PgBackendStatus *beentry; + LocalPgBackendStatus *local_beentry; + PgBackendStatus *beentry; Datum values[PG_STAT_GET_PROGRESS_COLS]; bool nulls[PG_STAT_GET_PROGRESS_COLS]; int i; @@ -613,14 +613,14 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS) if (has_privs_of_role(GetUserId(), beentry->st_userid)) { values[2] = ObjectIdGetDatum(beentry->st_progress_command_target); - for(i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++) - values[i+3] = Int64GetDatum(beentry->st_progress_param[i]); + for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++) + values[i + 3] = Int64GetDatum(beentry->st_progress_param[i]); } else { nulls[2] = true; for (i = 0; i < PGSTAT_NUM_PROGRESS_PARAM; i++) - nulls[i+3] = true; + nulls[i + 3] = true; } tuplestore_putvalues(tupstore, tupdesc, values, nulls); @@ -787,7 +787,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) proc = BackendPidGetProc(beentry->st_procpid); if (proc != NULL) { - uint32 raw_wait_event; + uint32 raw_wait_event; raw_wait_event = UINT32_ACCESS_ONCE(proc->wait_event_info); wait_event_type = pgstat_get_wait_event_type(raw_wait_event); diff --git a/src/backend/utils/adt/rangetypes_spgist.c b/src/backend/utils/adt/rangetypes_spgist.c index 7d35d581126..b89e90f908e 100644 --- a/src/backend/utils/adt/rangetypes_spgist.c +++ b/src/backend/utils/adt/rangetypes_spgist.c @@ -760,13 +760,14 @@ spg_range_quad_inner_consistent(PG_FUNCTION_ARGS) /* Save previous prefix if needed */ if (needPrevious) { - Datum previousCentroid; + Datum previousCentroid; - /* We know, that in->prefixDatum in this place is varlena, + /* + * We know, that in->prefixDatum in this place is varlena, * because it's range */ previousCentroid = datumCopy(in->prefixDatum, false, -1); - out->traversalValues[out->nNodes] = (void *)previousCentroid; + out->traversalValues[out->nNodes] = (void *) previousCentroid; } out->nodeNumbers[out->nNodes] = i - 1; out->nNodes++; diff --git a/src/backend/utils/adt/tsginidx.c b/src/backend/utils/adt/tsginidx.c index ebc11c9e4eb..b0963291433 100644 --- a/src/backend/utils/adt/tsginidx.c +++ b/src/backend/utils/adt/tsginidx.c @@ -184,8 +184,8 @@ checkcondition_gin_internal(GinChkVal *gcv, QueryOperand *val, ExecPhraseData *d int j; /* - * if any val requiring a weight is used or caller - * needs position information then set recheck flag + * if any val requiring a weight is used or caller needs position + * information then set recheck flag */ if (val->weight != 0 || data != NULL) *gcv->need_recheck = true; @@ -236,9 +236,10 @@ TS_execute_ternary(GinChkVal *gcv, QueryItem *curitem) return !result; case OP_PHRASE: + /* - * GIN doesn't contain any information about positions, - * treat OP_PHRASE as OP_AND with recheck requirement + * GIN doesn't contain any information about positions, treat + * OP_PHRASE as OP_AND with recheck requirement */ *gcv->need_recheck = true; /* FALL THRU */ diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c index eea6e0eae17..21a18bfbc44 100644 --- a/src/backend/utils/adt/tsquery.c +++ b/src/backend/utils/adt/tsquery.c @@ -24,12 +24,12 @@ #include "utils/pg_crc.h" /* FTS operator priorities, see ts_type.h */ -const int tsearch_op_priority[OP_COUNT] = +const int tsearch_op_priority[OP_COUNT] = { - 3, /* OP_NOT */ - 2, /* OP_AND */ - 1, /* OP_OR */ - 4 /* OP_PHRASE */ + 3, /* OP_NOT */ + 2, /* OP_AND */ + 1, /* OP_OR */ + 4 /* OP_PHRASE */ }; struct TSQueryParserStateData @@ -128,15 +128,15 @@ parse_phrase_operator(char *buf, int16 *distance) PHRASE_CLOSE, PHRASE_ERR, PHRASE_FINISH - } state = PHRASE_OPEN; + } state = PHRASE_OPEN; - char *ptr = buf; - char *endptr; - long l = 1; + char *ptr = buf; + char *endptr; + long l = 1; while (*ptr) { - switch(state) + switch (state) { case PHRASE_OPEN: Assert(t_iseq(ptr, '<')); @@ -192,7 +192,7 @@ parse_phrase_operator(char *buf, int16 *distance) } } - err: +err: *distance = -1; return buf; } @@ -440,18 +440,18 @@ makepol(TSQueryParserState state, PushFunction pushval, Datum opaque) { - int8 operator = 0; - ts_tokentype type; - int lenval = 0; - char *strval = NULL; + int8 operator = 0; + ts_tokentype type; + int lenval = 0; + char *strval = NULL; struct { - int8 op; - int16 distance; - } opstack[STACKDEPTH]; - int lenstack = 0; - int16 weight = 0; - bool prefix; + int8 op; + int16 distance; + } opstack[STACKDEPTH]; + int lenstack = 0; + int16 weight = 0; + bool prefix; /* since this function recurses, it could be driven to stack overflow */ check_stack_depth(); @@ -538,7 +538,7 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup) } else if (ptr[*pos].type == QI_VALSTOP) { - *needcleanup = true; /* we'll have to remove stop words */ + *needcleanup = true; /* we'll have to remove stop words */ (*pos)++; } else @@ -547,7 +547,7 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup) if (ptr[*pos].qoperator.oper == OP_NOT) { - ptr[*pos].qoperator.left = 1; /* fixed offset */ + ptr[*pos].qoperator.left = 1; /* fixed offset */ (*pos)++; /* process the only argument */ @@ -555,15 +555,15 @@ findoprnd_recurse(QueryItem *ptr, uint32 *pos, int nnodes, bool *needcleanup) } else { - QueryOperator *curitem = &ptr[*pos].qoperator; - int tmp = *pos; /* save current position */ + QueryOperator *curitem = &ptr[*pos].qoperator; + int tmp = *pos; /* save current position */ Assert(curitem->oper == OP_AND || curitem->oper == OP_OR || curitem->oper == OP_PHRASE); if (curitem->oper == OP_PHRASE) - *needcleanup = true; /* push OP_PHRASE down later */ + *needcleanup = true; /* push OP_PHRASE down later */ (*pos)++; @@ -669,7 +669,7 @@ parse_tsquery(char *buf, i = 0; foreach(cell, state.polstr) { - QueryItem *item = (QueryItem *) lfirst(cell); + QueryItem *item = (QueryItem *) lfirst(cell); switch (item->type) { @@ -696,8 +696,8 @@ parse_tsquery(char *buf, findoprnd(ptr, query->size, &needcleanup); /* - * QI_VALSTOP nodes should be cleaned and - * and OP_PHRASE should be pushed down + * QI_VALSTOP nodes should be cleaned and and OP_PHRASE should be pushed + * down */ if (needcleanup) return cleanup_fakeval_and_phrase(query); @@ -819,7 +819,7 @@ infix(INFIX *in, int parentPriority) } else if (in->curpol->qoperator.oper == OP_NOT) { - int priority = PRINT_PRIORITY(in->curpol); + int priority = PRINT_PRIORITY(in->curpol); if (priority < parentPriority) { @@ -852,8 +852,9 @@ infix(INFIX *in, int parentPriority) in->curpol++; if (priority < parentPriority || (op == OP_PHRASE && - (priority == parentPriority || /* phrases are not commutative! */ - parentPriority == OP_PRIORITY(OP_AND)))) + (priority == parentPriority || /* phrases are not + * commutative! */ + parentPriority == OP_PRIORITY(OP_AND)))) { needParenthesis = true; RESIZEBUF(in, 2); @@ -874,7 +875,7 @@ infix(INFIX *in, int parentPriority) infix(in, priority); /* print operator & right operand */ - RESIZEBUF(in, 3 + (2 + 10 /* distance */) + (nrm.cur - nrm.buf)); + RESIZEBUF(in, 3 + (2 + 10 /* distance */ ) + (nrm.cur - nrm.buf)); switch (op) { case OP_OR: @@ -923,7 +924,7 @@ tsqueryout(PG_FUNCTION_ARGS) nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen); *(nrm.cur) = '\0'; nrm.op = GETOPERAND(query); - infix(&nrm, -1 /* lowest priority */); + infix(&nrm, -1 /* lowest priority */ ); PG_FREE_IF_COPY(query, 0); PG_RETURN_CSTRING(nrm.buf); @@ -989,16 +990,16 @@ tsquerysend(PG_FUNCTION_ARGS) Datum tsqueryrecv(PG_FUNCTION_ARGS) { - StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); - TSQuery query; - int i, - len; - QueryItem *item; - int datalen; - char *ptr; - uint32 size; - const char **operands; - bool needcleanup; + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); + TSQuery query; + int i, + len; + QueryItem *item; + int datalen; + char *ptr; + uint32 size; + const char **operands; + bool needcleanup; size = pq_getmsgint(buf, sizeof(uint32)); if (size > (MaxAllocSize / sizeof(QueryItem))) diff --git a/src/backend/utils/adt/tsquery_cleanup.c b/src/backend/utils/adt/tsquery_cleanup.c index 0f6ef6f541f..6c74070e45e 100644 --- a/src/backend/utils/adt/tsquery_cleanup.c +++ b/src/backend/utils/adt/tsquery_cleanup.c @@ -224,8 +224,8 @@ clean_NOT(QueryItem *ptr, int *len) static NODE * clean_fakeval_intree(NODE *node, char *result, int *adddistance) { - char lresult = V_UNKNOWN, - rresult = V_UNKNOWN; + char lresult = V_UNKNOWN, + rresult = V_UNKNOWN; /* since this function recurses, it could be driven to stack overflow. */ check_stack_depth(); @@ -256,24 +256,26 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance) } else { - NODE *res = node; - int ndistance, ldistance = 0, rdistance = 0; + NODE *res = node; + int ndistance, + ldistance = 0, + rdistance = 0; ndistance = (node->valnode->qoperator.oper == OP_PHRASE) ? - node->valnode->qoperator.distance : - 0; + node->valnode->qoperator.distance : + 0; - node->left = clean_fakeval_intree(node->left, - &lresult, - ndistance ? &ldistance : NULL); + node->left = clean_fakeval_intree(node->left, + &lresult, + ndistance ? &ldistance : NULL); node->right = clean_fakeval_intree(node->right, &rresult, ndistance ? &rdistance : NULL); /* - * ndistance, ldistance and rdistance are greater than zero - * if their corresponding nodes are OP_PHRASE + * ndistance, ldistance and rdistance are greater than zero if their + * corresponding nodes are OP_PHRASE */ if (lresult == V_STOP && rresult == V_STOP) @@ -287,9 +289,10 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance) else if (lresult == V_STOP) { res = node->right; + /* - * propagate distance from current node to the - * right upper subtree. + * propagate distance from current node to the right upper + * subtree. */ if (adddistance && ndistance) *adddistance = rdistance; @@ -298,6 +301,7 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance) else if (rresult == V_STOP) { res = node->left; + /* * propagate distance from current node to the upper tree. */ @@ -324,7 +328,7 @@ clean_fakeval_intree(NODE *node, char *result, int *adddistance) static NODE * copyNODE(NODE *node) { - NODE *cnode = palloc(sizeof(NODE)); + NODE *cnode = palloc(sizeof(NODE)); /* since this function recurses, it could be driven to stack overflow. */ check_stack_depth(); @@ -345,7 +349,7 @@ copyNODE(NODE *node) static NODE * makeNODE(int8 op, NODE *left, NODE *right) { - NODE *node = palloc(sizeof(NODE)); + NODE *node = palloc(sizeof(NODE)); /* zeroing allocation to prevent difference in unused bytes */ node->valnode = palloc0(sizeof(QueryItem)); @@ -368,15 +372,15 @@ makeNODE(int8 op, NODE *left, NODE *right) * <-> (<n>) operation since it's needed solely for the phrase operator. * * Rules: - * a <-> (b | c) => (a <-> b) | (a <-> c) - * (a | b) <-> c => (a <-> c) | (b <-> c) - * a <-> !b => a & !(a <-> b) - * !a <-> b => b & !(a <-> b) + * a <-> (b | c) => (a <-> b) | (a <-> c) + * (a | b) <-> c => (a <-> c) | (b <-> c) + * a <-> !b => a & !(a <-> b) + * !a <-> b => b & !(a <-> b) * * Warnings for readers: * a <-> b != b <-> a * - * a <n> (b <n> c) != (a <n> b) <n> c since the phrase lengths are: + * a <n> (b <n> c) != (a <n> b) <n> c since the phrase lengths are: * n 2n-1 */ static NODE * @@ -397,7 +401,7 @@ normalize_phrase_tree(NODE *node) { /* eliminate NOT sequence */ while (node->valnode->type == QI_OPR && - node->valnode->qoperator.oper == node->right->valnode->qoperator.oper) + node->valnode->qoperator.oper == node->right->valnode->qoperator.oper) { node = node->right->right; } @@ -406,19 +410,19 @@ normalize_phrase_tree(NODE *node) } else if (node->valnode->qoperator.oper == OP_PHRASE) { - int16 distance; - NODE *X; + int16 distance; + NODE *X; node->left = normalize_phrase_tree(node->left); node->right = normalize_phrase_tree(node->right); if (NODE_PRIORITY(node) <= NODE_PRIORITY(node->right) && NODE_PRIORITY(node) <= NODE_PRIORITY(node->left)) - return node; + return node; /* - * We can't swap left-right and works only with left child - * because of a <-> b != b <-> a + * We can't swap left-right and works only with left child because of + * a <-> b != b <-> a */ distance = node->valnode->qoperator.distance; @@ -464,8 +468,8 @@ normalize_phrase_tree(NODE *node) /* no-op */ break; default: - elog(ERROR,"Wrong type of tsquery node: %d", - node->right->valnode->qoperator.oper); + elog(ERROR, "Wrong type of tsquery node: %d", + node->right->valnode->qoperator.oper); } } @@ -476,10 +480,10 @@ normalize_phrase_tree(NODE *node) * if the node is still OP_PHRASE, check the left subtree, * otherwise the whole node will be transformed later. */ - switch(node->left->valnode->qoperator.oper) + switch (node->left->valnode->qoperator.oper) { case OP_AND: - /* (a & b) <-> c => (a <-> c) & (b <-> c) */ + /* (a & b) <-> c => (a <-> c) & (b <-> c) */ node = makeNODE(OP_AND, makeNODE(OP_PHRASE, node->left->left, @@ -515,15 +519,15 @@ normalize_phrase_tree(NODE *node) /* no-op */ break; default: - elog(ERROR,"Wrong type of tsquery node: %d", - node->left->valnode->qoperator.oper); + elog(ERROR, "Wrong type of tsquery node: %d", + node->left->valnode->qoperator.oper); } } /* continue transformation */ node = normalize_phrase_tree(node); } - else /* AND or OR */ + else /* AND or OR */ { node->left = normalize_phrase_tree(node->left); node->right = normalize_phrase_tree(node->right); @@ -538,7 +542,7 @@ normalize_phrase_tree(NODE *node) static int32 calcstrlen(NODE *node) { - int32 size = 0; + int32 size = 0; if (node->valnode->type == QI_VAL) { diff --git a/src/backend/utils/adt/tsquery_op.c b/src/backend/utils/adt/tsquery_op.c index 5ea02c41c7e..a574b4b2573 100644 --- a/src/backend/utils/adt/tsquery_op.c +++ b/src/backend/utils/adt/tsquery_op.c @@ -147,10 +147,10 @@ Datum tsquery_phrase(PG_FUNCTION_ARGS) { PG_RETURN_POINTER(DirectFunctionCall3( - tsquery_phrase_distance, - PG_GETARG_DATUM(0), - PG_GETARG_DATUM(1), - Int32GetDatum(1))); + tsquery_phrase_distance, + PG_GETARG_DATUM(0), + PG_GETARG_DATUM(1), + Int32GetDatum(1))); } Datum diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c index ab47b763eeb..32023821b3f 100644 --- a/src/backend/utils/adt/tsrank.c +++ b/src/backend/utils/adt/tsrank.c @@ -366,8 +366,8 @@ calc_rank(const float *w, TSVector t, TSQuery q, int32 method) /* XXX: What about NOT? */ res = (item->type == QI_OPR && (item->qoperator.oper == OP_AND || item->qoperator.oper == OP_PHRASE)) ? - calc_rank_and(w, t, q) : - calc_rank_or(w, t, q); + calc_rank_and(w, t, q) : + calc_rank_or(w, t, q); if (res < 0) res = 1e-20f; @@ -498,17 +498,21 @@ ts_rank_tt(PG_FUNCTION_ARGS) typedef struct { - union { - struct { /* compiled doc representation */ + union + { + struct + { /* compiled doc representation */ QueryItem **items; int16 nitem; - } query; - struct { /* struct is used for preparing doc representation */ + } query; + struct + { /* struct is used for preparing doc + * representation */ QueryItem *item; WordEntry *entry; - } map; - } data; - WordEntryPos pos; + } map; + } data; + WordEntryPos pos; } DocRepresentation; static int @@ -536,16 +540,16 @@ compareDocR(const void *va, const void *vb) #define MAXQROPOS MAXENTRYPOS typedef struct { - bool operandexists; - bool reverseinsert; /* indicates insert order, - true means descending order */ - uint32 npos; - WordEntryPos pos[MAXQROPOS]; + bool operandexists; + bool reverseinsert; /* indicates insert order, true means + * descending order */ + uint32 npos; + WordEntryPos pos[MAXQROPOS]; } QueryRepresentationOperand; typedef struct { - TSQuery query; + TSQuery query; QueryRepresentationOperand *operandData; } QueryRepresentation; @@ -555,8 +559,8 @@ typedef struct static bool checkcondition_QueryOperand(void *checkval, QueryOperand *val, ExecPhraseData *data) { - QueryRepresentation *qr = (QueryRepresentation *) checkval; - QueryRepresentationOperand *opData = QR_GET_OPERAND_DATA(qr, val); + QueryRepresentation *qr = (QueryRepresentation *) checkval; + QueryRepresentationOperand *opData = QR_GET_OPERAND_DATA(qr, val); if (!opData->operandexists) return false; @@ -584,9 +588,9 @@ typedef struct static void resetQueryRepresentation(QueryRepresentation *qr, bool reverseinsert) { - int i; + int i; - for(i = 0; i < qr->query->size; i++) + for (i = 0; i < qr->query->size; i++) { qr->operandData[i].operandexists = false; qr->operandData[i].reverseinsert = reverseinsert; @@ -597,8 +601,8 @@ resetQueryRepresentation(QueryRepresentation *qr, bool reverseinsert) static void fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry) { - int i; - int lastPos; + int i; + int lastPos; QueryRepresentationOperand *opData; for (i = 0; i < entry->data.query.nitem; i++) @@ -619,14 +623,14 @@ fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry) } lastPos = opData->reverseinsert ? - (MAXQROPOS - opData->npos) : - (opData->npos - 1); + (MAXQROPOS - opData->npos) : + (opData->npos - 1); if (WEP_GETPOS(opData->pos[lastPos]) != WEP_GETPOS(entry->pos)) { lastPos = opData->reverseinsert ? - (MAXQROPOS - 1 - opData->npos) : - (opData->npos); + (MAXQROPOS - 1 - opData->npos) : + (opData->npos); opData->pos[lastPos] = entry->pos; opData->npos++; @@ -637,9 +641,9 @@ fillQueryRepresentationData(QueryRepresentation *qr, DocRepresentation *entry) static bool Cover(DocRepresentation *doc, int len, QueryRepresentation *qr, CoverExt *ext) { - DocRepresentation *ptr; - int lastpos = ext->pos; - bool found = false; + DocRepresentation *ptr; + int lastpos = ext->pos; + bool found = false; /* * since this function recurses, it could be driven to stack overflow. @@ -720,7 +724,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen) WordEntry *entry, *firstentry; WordEntryPos *post; - int32 dimt, /* number of 'post' items */ + int32 dimt, /* number of 'post' items */ j, i, nitem; @@ -731,8 +735,8 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen) doc = (DocRepresentation *) palloc(sizeof(DocRepresentation) * len); /* - * Iterate through query to make DocRepresentaion for words and it's entries - * satisfied by query + * Iterate through query to make DocRepresentaion for words and it's + * entries satisfied by query */ for (i = 0; i < qr->query->size; i++) { @@ -787,9 +791,9 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen) if (cur > 0) { - DocRepresentation *rptr = doc + 1, - *wptr = doc, - storage; + DocRepresentation *rptr = doc + 1, + *wptr = doc, + storage; /* * Sort representation in ascending order by pos and entry @@ -806,8 +810,8 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen) while (rptr - doc < cur) { - if (rptr->pos == (rptr-1)->pos && - rptr->data.map.entry == (rptr-1)->data.map.entry) + if (rptr->pos == (rptr - 1)->pos && + rptr->data.map.entry == (rptr - 1)->data.map.entry) { storage.data.query.items[storage.data.query.nitem] = rptr->data.map.item; storage.data.query.nitem++; @@ -865,7 +869,7 @@ calc_rank_cd(const float4 *arrdata, TSVector txt, TSQuery query, int method) qr.query = query; qr.operandData = (QueryRepresentationOperand *) - palloc0(sizeof(QueryRepresentationOperand) * query->size); + palloc0(sizeof(QueryRepresentationOperand) * query->size); doc = get_docrep(txt, &qr, &doclen); if (!doc) diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index 591e59cf990..6117ba9b3e4 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -66,7 +66,7 @@ typedef struct #define STATHDRSIZE (offsetof(TSVectorStat, data)) static Datum tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column); -static int tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len); +static int tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len); /* * Order: haspos, len, word, for all positions (pos, weight) @@ -276,16 +276,20 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS) switch (char_weight) { - case 'A': case 'a': + case 'A': + case 'a': weight = 3; break; - case 'B': case 'b': + case 'B': + case 'b': weight = 2; break; - case 'C': case 'c': + case 'C': + case 'c': weight = 1; break; - case 'D': case 'd': + case 'D': + case 'd': weight = 0; break; default: @@ -301,15 +305,15 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS) &dlexemes, &nulls, &nlexemes); /* - * Assuming that lexemes array is significantly shorter than tsvector - * we can iterate through lexemes performing binary search - * of each lexeme from lexemes in tsvector. + * Assuming that lexemes array is significantly shorter than tsvector we + * can iterate through lexemes performing binary search of each lexeme + * from lexemes in tsvector. */ for (i = 0; i < nlexemes; i++) { - char *lex; - int lex_len, - lex_pos; + char *lex; + int lex_len, + lex_pos; if (nulls[i]) ereport(ERROR, @@ -323,6 +327,7 @@ tsvector_setweight_by_filter(PG_FUNCTION_ARGS) if (lex_pos >= 0 && (j = POSDATALEN(tsout, entry + lex_pos)) != 0) { WordEntryPos *p = POSDATAPTR(tsout, entry + lex_pos); + while (j--) { WEP_SETWEIGHT(*p, weight); @@ -393,18 +398,18 @@ tsvector_bsearch(const TSVector tsv, char *lexeme, int lexeme_len) while (StopLow < StopHigh) { - StopMiddle = (StopLow + StopHigh)/2; + StopMiddle = (StopLow + StopHigh) / 2; cmp = tsCompareString(lexeme, lexeme_len, - STRPTR(tsv) + arrin[StopMiddle].pos, - arrin[StopMiddle].len, - false); + STRPTR(tsv) + arrin[StopMiddle].pos, + arrin[StopMiddle].len, + false); if (cmp < 0) StopHigh = StopMiddle; else if (cmp > 0) StopLow = StopMiddle + 1; - else /* found it */ + else /* found it */ return StopMiddle; } @@ -440,13 +445,15 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete, *arrout; char *data = STRPTR(tsv), *dataout; - int i, j, k, + int i, + j, + k, curoff; /* * Here we overestimates tsout size, since we don't know exact size - * occupied by positions and weights. We will set exact size later - * after a pass through TSVector. + * occupied by positions and weights. We will set exact size later after a + * pass through TSVector. */ tsout = (TSVector) palloc0(VARSIZE(tsv)); arrout = ARRPTR(tsout); @@ -465,10 +472,11 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete, { /* * Here we should check whether current i is present in - * indices_to_delete or not. Since indices_to_delete is already - * sorted we can advance it index only when we have match. + * indices_to_delete or not. Since indices_to_delete is already sorted + * we can advance it index only when we have match. */ - if (k < indices_count && i == indices_to_delete[k]){ + if (k < indices_count && i == indices_to_delete[k]) + { k++; continue; } @@ -481,8 +489,9 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete, curoff += arrin[i].len; if (arrin[i].haspos) { - int len = POSDATALEN(tsv, arrin+i) * sizeof(WordEntryPos) + - sizeof(uint16); + int len = POSDATALEN(tsv, arrin + i) * sizeof(WordEntryPos) + + sizeof(uint16); + curoff = SHORTALIGN(curoff); memcpy(dataout + curoff, STRPTR(tsv) + SHORTALIGN(arrin[i].pos + arrin[i].len), @@ -494,9 +503,10 @@ tsvector_delete_by_indices(TSVector tsv, int *indices_to_delete, } /* - * After the pass through TSVector k should equals exactly to indices_count. - * If it isn't then the caller provided us with indices outside of - * [0, tsv->size) range and estimation of tsout's size is wrong. + * After the pass through TSVector k should equals exactly to + * indices_count. If it isn't then the caller provided us with indices + * outside of [0, tsv->size) range and estimation of tsout's size is + * wrong. */ Assert(k == indices_count); @@ -538,7 +548,8 @@ tsvector_delete_arr(PG_FUNCTION_ARGS) TSVector tsin = PG_GETARG_TSVECTOR(0), tsout; ArrayType *lexemes = PG_GETARG_ARRAYTYPE_P(1); - int i, nlex, + int i, + nlex, skip_count, *skip_indices; Datum *dlexemes; @@ -548,16 +559,16 @@ tsvector_delete_arr(PG_FUNCTION_ARGS) &dlexemes, &nulls, &nlex); /* - * In typical use case array of lexemes to delete is relatively small. - * So here we optimizing things for that scenario: iterate through lexarr + * In typical use case array of lexemes to delete is relatively small. So + * here we optimizing things for that scenario: iterate through lexarr * performing binary search of each lexeme from lexarr in tsvector. */ skip_indices = palloc0(nlex * sizeof(int)); for (i = skip_count = 0; i < nlex; i++) { - char *lex; - int lex_len, - lex_pos; + char *lex; + int lex_len, + lex_pos; if (nulls[i]) ereport(ERROR, @@ -583,15 +594,15 @@ tsvector_delete_arr(PG_FUNCTION_ARGS) /* * Expand tsvector as table with following columns: - * lexeme: lexeme text - * positions: integer array of lexeme positions - * weights: char array of weights corresponding to positions + * lexeme: lexeme text + * positions: integer array of lexeme positions + * weights: char array of weights corresponding to positions */ Datum tsvector_unnest(PG_FUNCTION_ARGS) { - FuncCallContext *funcctx; - TSVector tsin; + FuncCallContext *funcctx; + TSVector tsin; if (SRF_IS_FIRSTCALL()) { @@ -629,8 +640,8 @@ tsvector_unnest(PG_FUNCTION_ARGS) Datum values[3]; values[0] = PointerGetDatum( - cstring_to_text_with_len(data + arrin[i].pos, arrin[i].len) - ); + cstring_to_text_with_len(data + arrin[i].pos, arrin[i].len) + ); if (arrin[i].haspos) { @@ -641,25 +652,25 @@ tsvector_unnest(PG_FUNCTION_ARGS) /* * Internally tsvector stores position and weight in the same - * uint16 (2 bits for weight, 14 for position). Here we extract that - * in two separate arrays. + * uint16 (2 bits for weight, 14 for position). Here we extract + * that in two separate arrays. */ posv = _POSVECPTR(tsin, arrin + i); positions = palloc(posv->npos * sizeof(Datum)); - weights = palloc(posv->npos * sizeof(Datum)); + weights = palloc(posv->npos * sizeof(Datum)); for (j = 0; j < posv->npos; j++) { positions[j] = Int16GetDatum(WEP_GETPOS(posv->pos[j])); weight = 'D' - WEP_GETWEIGHT(posv->pos[j]); weights[j] = PointerGetDatum( - cstring_to_text_with_len(&weight, 1) - ); + cstring_to_text_with_len(&weight, 1) + ); } values[1] = PointerGetDatum( - construct_array(positions, posv->npos, INT2OID, 2, true, 's')); + construct_array(positions, posv->npos, INT2OID, 2, true, 's')); values[2] = PointerGetDatum( - construct_array(weights, posv->npos, TEXTOID, -1, false, 'i')); + construct_array(weights, posv->npos, TEXTOID, -1, false, 'i')); } else { @@ -682,19 +693,19 @@ tsvector_unnest(PG_FUNCTION_ARGS) Datum tsvector_to_array(PG_FUNCTION_ARGS) { - TSVector tsin = PG_GETARG_TSVECTOR(0); - WordEntry *arrin = ARRPTR(tsin); - Datum *elements; - int i; - ArrayType *array; + TSVector tsin = PG_GETARG_TSVECTOR(0); + WordEntry *arrin = ARRPTR(tsin); + Datum *elements; + int i; + ArrayType *array; elements = palloc(tsin->size * sizeof(Datum)); for (i = 0; i < tsin->size; i++) { elements[i] = PointerGetDatum( - cstring_to_text_with_len(STRPTR(tsin) + arrin[i].pos, arrin[i].len) - ); + cstring_to_text_with_len(STRPTR(tsin) + arrin[i].pos, arrin[i].len) + ); } array = construct_array(elements, tsin->size, TEXTOID, -1, false, 'i'); @@ -742,8 +753,8 @@ array_to_tsvector(PG_FUNCTION_ARGS) for (i = 0; i < nitems; i++) { - char *lex = VARDATA(dlexemes[i]); - int lex_len = VARSIZE_ANY_EXHDR(dlexemes[i]); + char *lex = VARDATA(dlexemes[i]); + int lex_len = VARSIZE_ANY_EXHDR(dlexemes[i]); memcpy(cur, lex, lex_len); arrout[i].haspos = 0; @@ -772,7 +783,8 @@ tsvector_filter(PG_FUNCTION_ARGS) Datum *dweights; bool *nulls; int nweights; - int i, j; + int i, + j; int cur_pos = 0; char mask = 0; @@ -781,7 +793,7 @@ tsvector_filter(PG_FUNCTION_ARGS) for (i = 0; i < nweights; i++) { - char char_weight; + char char_weight; if (nulls[i]) ereport(ERROR, @@ -791,22 +803,26 @@ tsvector_filter(PG_FUNCTION_ARGS) char_weight = DatumGetChar(dweights[i]); switch (char_weight) { - case 'A': case 'a': + case 'A': + case 'a': mask = mask | 8; break; - case 'B': case 'b': + case 'B': + case 'b': mask = mask | 4; break; - case 'C': case 'c': + case 'C': + case 'c': mask = mask | 2; break; - case 'D': case 'd': + case 'D': + case 'd': mask = mask | 1; break; default: - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("unrecognized weight: \"%c\"", char_weight))); + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("unrecognized weight: \"%c\"", char_weight))); } } @@ -818,16 +834,16 @@ tsvector_filter(PG_FUNCTION_ARGS) for (i = j = 0; i < tsin->size; i++) { WordEntryPosVector *posvin, - *posvout; - int npos = 0; - int k; + *posvout; + int npos = 0; + int k; if (!arrin[i].haspos) continue; - posvin = _POSVECPTR(tsin, arrin + i); + posvin = _POSVECPTR(tsin, arrin + i); posvout = (WordEntryPosVector *) - (dataout + SHORTALIGN(cur_pos + arrin[i].len)); + (dataout + SHORTALIGN(cur_pos + arrin[i].len)); for (k = 0; k < posvin->npos; k++) { @@ -846,8 +862,8 @@ tsvector_filter(PG_FUNCTION_ARGS) memcpy(dataout + cur_pos, datain + arrin[i].pos, arrin[i].len); posvout->npos = npos; cur_pos += SHORTALIGN(arrin[i].len); - cur_pos += POSDATALEN(tsout, arrout+j) * sizeof(WordEntryPos) + - sizeof(uint16); + cur_pos += POSDATALEN(tsout, arrout + j) * sizeof(WordEntryPos) + + sizeof(uint16); j++; } @@ -1129,11 +1145,11 @@ static bool checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val, ExecPhraseData *data) { - bool result = false; + bool result = false; if (entry->haspos && (val->weight || data)) { - WordEntryPosVector *posvec; + WordEntryPosVector *posvec; /* * We can't use the _POSVECPTR macro here because the pointer to the @@ -1144,8 +1160,8 @@ checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val, if (val->weight && data) { - WordEntryPos *posvec_iter = posvec->pos; - WordEntryPos *dptr; + WordEntryPos *posvec_iter = posvec->pos; + WordEntryPos *dptr; /* * Filter position information by weights @@ -1173,7 +1189,7 @@ checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val, } else if (val->weight) { - WordEntryPos *posvec_iter = posvec->pos; + WordEntryPos *posvec_iter = posvec->pos; /* Is there a position with a matching weight? */ while (posvec_iter < posvec->pos + posvec->npos) @@ -1181,16 +1197,16 @@ checkclass_str(CHKVAL *chkval, WordEntry *entry, QueryOperand *val, if (val->weight & (1 << WEP_GETWEIGHT(*posvec_iter))) { result = true; - break; /* no need to go further */ + break; /* no need to go further */ } posvec_iter++; } } - else /* data != NULL */ + else /* data != NULL */ { data->npos = posvec->npos; - data->pos = posvec->pos; + data->pos = posvec->pos; data->allocated = false; result = true; } @@ -1213,7 +1229,7 @@ static int uniqueLongPos(WordEntryPos *pos, int npos) { WordEntryPos *pos_iter, - *result; + *result; if (npos <= 1) return npos; @@ -1273,9 +1289,10 @@ checkcondition_str(void *checkval, QueryOperand *val, ExecPhraseData *data) if ((!res || data) && val->prefix) { - WordEntryPos *allpos = NULL; - int npos = 0, - totalpos = 0; + WordEntryPos *allpos = NULL; + int npos = 0, + totalpos = 0; + /* * there was a failed exact search, so we should scan further to find * a prefix match. We also need to do so if caller needs position info @@ -1355,11 +1372,11 @@ TS_phrase_execute(QueryItem *curitem, } else { - ExecPhraseData Ldata = {0, false, NULL}, - Rdata = {0, false, NULL}; - WordEntryPos *Lpos, - *Rpos, - *pos_iter = NULL; + ExecPhraseData Ldata = {0, false, NULL}, + Rdata = {0, false, NULL}; + WordEntryPos *Lpos, + *Rpos, + *pos_iter = NULL; Assert(curitem->qoperator.oper == OP_PHRASE); @@ -1371,22 +1388,24 @@ TS_phrase_execute(QueryItem *curitem, return false; /* - * if at least one of the operands has no position - * information, fallback to AND operation. + * if at least one of the operands has no position information, + * fallback to AND operation. */ if (Ldata.npos == 0 || Rdata.npos == 0) return true; /* - * Result of the operation is a list of the - * corresponding positions of RIGHT operand. + * Result of the operation is a list of the corresponding positions of + * RIGHT operand. */ if (data) { if (!Rdata.allocated) + /* - * OP_PHRASE is based on the OP_AND, so the number of resulting - * positions could not be greater than the total amount of operands. + * OP_PHRASE is based on the OP_AND, so the number of + * resulting positions could not be greater than the total + * amount of operands. */ data->pos = palloc(sizeof(WordEntryPos) * Min(Ldata.npos, Rdata.npos)); else @@ -1423,8 +1442,8 @@ TS_phrase_execute(QueryItem *curitem, *pos_iter = WEP_GETPOS(*Rpos); pos_iter++; - break; /* We need to build a unique result - * array, so go to the next Rpos */ + break; /* We need to build a unique result + * array, so go to the next Rpos */ } else { @@ -1439,8 +1458,8 @@ TS_phrase_execute(QueryItem *curitem, else { /* - * Go to the next Rpos, because Lpos - * is ahead of the current Rpos + * Go to the next Rpos, because Lpos is ahead of the + * current Rpos */ break; } @@ -1477,14 +1496,14 @@ TS_phrase_execute(QueryItem *curitem, */ bool TS_execute(QueryItem *curitem, void *checkval, bool calcnot, - bool (*chkcond) (void *checkval, QueryOperand *val, ExecPhraseData *data)) + bool (*chkcond) (void *checkval, QueryOperand *val, ExecPhraseData *data)) { /* since this function recurses, it could be driven to stack overflow */ check_stack_depth(); if (curitem->type == QI_VAL) return chkcond(checkval, (QueryOperand *) curitem, - NULL /* we don't need position info */); + NULL /* we don't need position info */ ); switch (curitem->qoperator.oper) { @@ -1546,6 +1565,7 @@ tsquery_requires_match(QueryItem *curitem) return false; case OP_PHRASE: + /* * Treat OP_PHRASE as OP_AND here */ @@ -1972,7 +1992,7 @@ ts_stat_sql(MemoryContext persistentContext, text *txt, text *ws) if (SPI_tuptable == NULL || SPI_tuptable->tupdesc->natts != 1 || !IsBinaryCoercible(SPI_gettypeid(SPI_tuptable->tupdesc, 1), - TSVECTOROID)) + TSVECTOROID)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("ts_stat query must return one tsvector column"))); @@ -2160,7 +2180,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column) errmsg("tsvector column \"%s\" does not exist", trigger->tgargs[0]))); if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, tsvector_attr_num), - TSVECTOROID)) + TSVECTOROID)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("column \"%s\" is not of tsvector type", @@ -2178,7 +2198,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column) errmsg("configuration column \"%s\" does not exist", trigger->tgargs[1]))); if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, config_attr_num), - REGCONFIGOID)) + REGCONFIGOID)) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("column \"%s\" is not of regconfig type", diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c index a6d5c18312b..c59e74da3d1 100644 --- a/src/backend/utils/adt/uuid.c +++ b/src/backend/utils/adt/uuid.c @@ -44,8 +44,8 @@ static void string_to_uuid(const char *source, pg_uuid_t *uuid); static int uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2); static int uuid_fast_cmp(Datum x, Datum y, SortSupport ssup); static int uuid_cmp_abbrev(Datum x, Datum y, SortSupport ssup); -static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup); -static Datum uuid_abbrev_convert(Datum original, SortSupport ssup); +static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup); +static Datum uuid_abbrev_convert(Datum original, SortSupport ssup); Datum uuid_in(PG_FUNCTION_ARGS) @@ -245,15 +245,15 @@ uuid_cmp(PG_FUNCTION_ARGS) Datum uuid_sortsupport(PG_FUNCTION_ARGS) { - SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); + SortSupport ssup = (SortSupport) PG_GETARG_POINTER(0); ssup->comparator = uuid_fast_cmp; ssup->ssup_extra = NULL; if (ssup->abbreviate) { - uuid_sortsupport_state *uss; - MemoryContext oldcontext; + uuid_sortsupport_state *uss; + MemoryContext oldcontext; oldcontext = MemoryContextSwitchTo(ssup->ssup_cxt); @@ -310,8 +310,8 @@ uuid_cmp_abbrev(Datum x, Datum y, SortSupport ssup) static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup) { - uuid_sortsupport_state *uss = ssup->ssup_extra; - double abbr_card; + uuid_sortsupport_state *uss = ssup->ssup_extra; + double abbr_card; if (memtupcount < 10000 || uss->input_count < 10000 || !uss->estimating) return false; @@ -340,8 +340,8 @@ uuid_abbrev_abort(int memtupcount, SortSupport ssup) /* * Target minimum cardinality is 1 per ~2k of non-null inputs. 0.5 row * fudge factor allows us to abort earlier on genuinely pathological data - * where we've had exactly one abbreviated value in the first 2k (non-null) - * rows. + * where we've had exactly one abbreviated value in the first 2k + * (non-null) rows. */ if (abbr_card < uss->input_count / 2000.0 + 0.5) { @@ -349,7 +349,7 @@ uuid_abbrev_abort(int memtupcount, SortSupport ssup) if (trace_sort) elog(LOG, "uuid_abbrev: aborting abbreviation at cardinality %f" - " below threshold %f after " INT64_FORMAT " values (%d rows)", + " below threshold %f after " INT64_FORMAT " values (%d rows)", abbr_card, uss->input_count / 2000.0 + 0.5, uss->input_count, memtupcount); #endif @@ -376,9 +376,9 @@ uuid_abbrev_abort(int memtupcount, SortSupport ssup) static Datum uuid_abbrev_convert(Datum original, SortSupport ssup) { - uuid_sortsupport_state *uss = ssup->ssup_extra; - pg_uuid_t *authoritative = DatumGetUUIDP(original); - Datum res; + uuid_sortsupport_state *uss = ssup->ssup_extra; + pg_uuid_t *authoritative = DatumGetUUIDP(original); + Datum res; memcpy(&res, authoritative->data, sizeof(Datum)); uss->input_count += 1; @@ -400,9 +400,9 @@ uuid_abbrev_convert(Datum original, SortSupport ssup) * Byteswap on little-endian machines. * * This is needed so that uuid_cmp_abbrev() (an unsigned integer 3-way - * comparator) works correctly on all platforms. If we didn't do this, the - * comparator would have to call memcmp() with a pair of pointers to the - * first byte of each abbreviated key, which is slower. + * comparator) works correctly on all platforms. If we didn't do this, + * the comparator would have to call memcmp() with a pair of pointers to + * the first byte of each abbreviated key, which is slower. */ res = DatumBigEndianToNative(res); diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index b10027ff517..a869e858bca 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -5055,9 +5055,9 @@ text_format(PG_FUNCTION_ARGS) /* should not get here, because of previous check */ ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("unrecognized format() type specifier \"%c\"", - *cp), - errhint("For a single \"%%\" use \"%%%%\"."))); + errmsg("unrecognized format() type specifier \"%c\"", + *cp), + errhint("For a single \"%%\" use \"%%%%\"."))); break; } } diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index cb26d79afb0..13ae6add036 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -1819,9 +1819,9 @@ get_rel_tablespace(Oid relid) char get_rel_persistence(Oid relid) { - HeapTuple tp; - Form_pg_class reltup; - char result; + HeapTuple tp; + Form_pg_class reltup; + char result; tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); if (!HeapTupleIsValid(tp)) diff --git a/src/backend/utils/cache/plancache.c b/src/backend/utils/cache/plancache.c index 8fd9f2b573f..005e4b7f1c3 100644 --- a/src/backend/utils/cache/plancache.c +++ b/src/backend/utils/cache/plancache.c @@ -106,7 +106,7 @@ static void PlanCacheRelCallback(Datum arg, Oid relid); static void PlanCacheFuncCallback(Datum arg, int cacheid, uint32 hashvalue); static void PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue); static void PlanCacheUserMappingCallback(Datum arg, int cacheid, - uint32 hashvalue); + uint32 hashvalue); /* @@ -610,10 +610,11 @@ RevalidateCachedQuery(CachedPlanSource *plansource) plansource->is_valid = false; /* - * If we have a join pushed down to the foreign server and the current user - * is different from the one for which the plan was created, invalidate the - * generic plan since user mapping for the new user might make the join - * unsafe to push down, or change which user mapping is used. + * If we have a join pushed down to the foreign server and the current + * user is different from the one for which the plan was created, + * invalidate the generic plan since user mapping for the new user might + * make the join unsafe to push down, or change which user mapping is + * used. */ if (plansource->is_valid && plansource->gplan && @@ -901,7 +902,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist, bool spi_pushed; MemoryContext plan_context; MemoryContext oldcxt = CurrentMemoryContext; - ListCell *lc; + ListCell *lc; /* * Normally the querytree should be valid already, but if it's not, @@ -1016,7 +1017,7 @@ BuildCachedPlan(CachedPlanSource *plansource, List *qlist, plan->has_foreign_join = false; foreach(lc, plist) { - PlannedStmt *plan_stmt = (PlannedStmt *) lfirst(lc); + PlannedStmt *plan_stmt = (PlannedStmt *) lfirst(lc); if (IsA(plan_stmt, PlannedStmt)) plan->has_foreign_join = @@ -1888,9 +1889,9 @@ PlanCacheSysCallback(Datum arg, int cacheid, uint32 hashvalue) /* * PlanCacheUserMappingCallback - * Syscache inval callback function for user mapping cache invalidation. + * Syscache inval callback function for user mapping cache invalidation. * - * Invalidates plans which have pushed down foreign joins. + * Invalidates plans which have pushed down foreign joins. */ static void PlanCacheUserMappingCallback(Datum arg, int cacheid, uint32 hashvalue) @@ -1911,9 +1912,9 @@ PlanCacheUserMappingCallback(Datum arg, int cacheid, uint32 hashvalue) /* * If the plan has pushed down foreign joins, those join may become - * unsafe to push down because of user mapping changes. Invalidate only - * the generic plan, since changes to user mapping do not invalidate the - * parse tree. + * unsafe to push down because of user mapping changes. Invalidate + * only the generic plan, since changes to user mapping do not + * invalidate the parse tree. */ if (plansource->gplan && plansource->gplan->has_foreign_join) plansource->gplan->is_valid = false; diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 1b7b99548c5..afb6c8772da 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -5251,9 +5251,9 @@ RelationIdIsInInitFile(Oid relationId) bool RelationHasUnloggedIndex(Relation rel) { - List *indexoidlist; - ListCell *indexoidscan; - bool result = false; + List *indexoidlist; + ListCell *indexoidscan; + bool result = false; indexoidlist = RelationGetIndexList(rel); diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 740f089ccdb..78d441d1987 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -150,8 +150,8 @@ static int recursion_depth = 0; /* to detect actual recursion */ * both log_line_prefix and csv logs. */ -static struct timeval saved_timeval; -static bool saved_timeval_set = false; +static struct timeval saved_timeval; +static bool saved_timeval_set = false; #define FORMATTED_TS_LEN 128 static char formatted_start_time[FORMATTED_TS_LEN]; @@ -1467,9 +1467,9 @@ EmitErrorReport(void) * mechanisms. * * The log hook has access to both the translated and original English - * error message text, which is passed through to allow it to be used - * as a message identifier. Note that the original text is not available - * for detail, detail_log, hint and context text elements. + * error message text, which is passed through to allow it to be used as a + * message identifier. Note that the original text is not available for + * detail, detail_log, hint and context text elements. */ if (edata->output_to_server && emit_log_hook) (*emit_log_hook) (edata); @@ -2467,7 +2467,7 @@ log_line_prefix(StringInfo buf, ErrorData *edata) break; case 'n': { - char strfbuf[128]; + char strfbuf[128]; if (!saved_timeval_set) { @@ -2476,7 +2476,7 @@ log_line_prefix(StringInfo buf, ErrorData *edata) } sprintf(strfbuf, "%ld.%03d", saved_timeval.tv_sec, - (int)(saved_timeval.tv_usec / 1000)); + (int) (saved_timeval.tv_usec / 1000)); if (padding != 0) appendStringInfo(buf, "%*s", padding, strfbuf); diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c index 1a9f70c5662..d35052aea6c 100644 --- a/src/backend/utils/hash/dynahash.c +++ b/src/backend/utils/hash/dynahash.c @@ -130,7 +130,7 @@ typedef struct slock_t mutex; /* spinlock */ long nentries; /* number of entries */ HASHELEMENT *freeList; /* list of free elements */ -} FreeListData; +} FreeListData; /* * Header structure for a hash table --- contains all changeable info diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index d13355bf668..d4625a6238f 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -482,7 +482,7 @@ InitializeSessionUserId(const char *rolename, Oid roleid) { HeapTuple roleTup; Form_pg_authid rform; - char *rname; + char *rname; /* * Don't do scans if we're bootstrapping, none of the system catalogs diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c index b3f1bc46d97..d17197267ef 100644 --- a/src/backend/utils/init/postinit.c +++ b/src/backend/utils/init/postinit.c @@ -192,6 +192,7 @@ PerformAuthentication(Port *port) * FIXME: [fork/exec] Ugh. Is there a way around this overhead? */ #ifdef EXEC_BACKEND + /* * load_hba() and load_ident() want to work within the PostmasterContext, * so create that if it doesn't exist (which it won't). We'll delete it @@ -870,9 +871,9 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username, { /* * If this is a background worker not bound to any particular - * database, we're done now. Everything that follows only makes - * sense if we are bound to a specific database. We do need to - * close the transaction we started before returning. + * database, we're done now. Everything that follows only makes sense + * if we are bound to a specific database. We do need to close the + * transaction we started before returning. */ if (!bootstrap) CommitTransactionCommand(); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 14d20429101..cf3eb1a4f14 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -2869,7 +2869,7 @@ static struct config_real ConfigureNamesReal[] = { {"parallel_setup_cost", PGC_USERSET, QUERY_TUNING_COST, gettext_noop("Sets the planner's estimate of the cost of " - "starting up worker processes for parallel query."), + "starting up worker processes for parallel query."), NULL }, ¶llel_setup_cost, @@ -5926,13 +5926,14 @@ set_config_option(const char *name, const char *value, * don't re-read the config file during backend start. * * In EXEC_BACKEND builds, this works differently: we load all - * non-default settings from the CONFIG_EXEC_PARAMS file during - * backend start. In that case we must accept PGC_SIGHUP - * settings, so as to have the same value as if we'd forked - * from the postmaster. This can also happen when using - * RestoreGUCState() within a background worker that needs to - * have the same settings as the user backend that started it. - * is_reload will be true when either situation applies. + * non-default settings from the CONFIG_EXEC_PARAMS file + * during backend start. In that case we must accept + * PGC_SIGHUP settings, so as to have the same value as if + * we'd forked from the postmaster. This can also happen when + * using RestoreGUCState() within a background worker that + * needs to have the same settings as the user backend that + * started it. is_reload will be true when either situation + * applies. */ if (IsUnderPostmaster && !is_reload) return -1; diff --git a/src/backend/utils/misc/pg_config.c b/src/backend/utils/misc/pg_config.c index 3d6b9f27c08..1fbdd1f4db8 100644 --- a/src/backend/utils/misc/pg_config.c +++ b/src/backend/utils/misc/pg_config.c @@ -25,17 +25,17 @@ Datum pg_config(PG_FUNCTION_ARGS) { - ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; - Tuplestorestate *tupstore; - HeapTuple tuple; - TupleDesc tupdesc; - AttInMetadata *attinmeta; - MemoryContext per_query_ctx; - MemoryContext oldcontext; - ConfigData *configdata; - size_t configdata_len; - char *values[2]; - int i = 0; + ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; + Tuplestorestate *tupstore; + HeapTuple tuple; + TupleDesc tupdesc; + AttInMetadata *attinmeta; + MemoryContext per_query_ctx; + MemoryContext oldcontext; + ConfigData *configdata; + size_t configdata_len; + char *values[2]; + int i = 0; /* check to see if caller supports us returning a tuplestore */ if (!rsinfo || !(rsinfo->allowedModes & SFRM_Materialize)) @@ -91,10 +91,10 @@ pg_config(PG_FUNCTION_ARGS) /* * SFRM_Materialize mode expects us to return a NULL Datum. The actual - * tuples are in our tuplestore and passed back through - * rsinfo->setResult. rsinfo->setDesc is set to the tuple description - * that we actually used to build our tuples with, so the caller can - * verify we did what it was expecting. + * tuples are in our tuplestore and passed back through rsinfo->setResult. + * rsinfo->setDesc is set to the tuple description that we actually used + * to build our tuples with, so the caller can verify we did what it was + * expecting. */ rsinfo->setDesc = tupdesc; MemoryContextSwitchTo(oldcontext); diff --git a/src/backend/utils/misc/pg_controldata.c b/src/backend/utils/misc/pg_controldata.c index 8552c0713b2..34ee76a237e 100644 --- a/src/backend/utils/misc/pg_controldata.c +++ b/src/backend/utils/misc/pg_controldata.c @@ -29,11 +29,11 @@ Datum pg_control_system(PG_FUNCTION_ARGS) { - Datum values[4]; - bool nulls[4]; - TupleDesc tupdesc; - HeapTuple htup; - ControlFileData *ControlFile; + Datum values[4]; + bool nulls[4]; + TupleDesc tupdesc; + HeapTuple htup; + ControlFileData *ControlFile; /* * Construct a tuple descriptor for the result row. This must match this @@ -73,13 +73,13 @@ pg_control_system(PG_FUNCTION_ARGS) Datum pg_control_checkpoint(PG_FUNCTION_ARGS) { - Datum values[19]; - bool nulls[19]; - TupleDesc tupdesc; - HeapTuple htup; - ControlFileData *ControlFile; - XLogSegNo segno; - char xlogfilename[MAXFNAMELEN]; + Datum values[19]; + bool nulls[19]; + TupleDesc tupdesc; + HeapTuple htup; + ControlFileData *ControlFile; + XLogSegNo segno; + char xlogfilename[MAXFNAMELEN]; /* * Construct a tuple descriptor for the result row. This must match this @@ -159,8 +159,8 @@ pg_control_checkpoint(PG_FUNCTION_ARGS) nulls[6] = false; values[7] = CStringGetTextDatum(psprintf("%u:%u", - ControlFile->checkPointCopy.nextXidEpoch, - ControlFile->checkPointCopy.nextXid)); + ControlFile->checkPointCopy.nextXidEpoch, + ControlFile->checkPointCopy.nextXid)); nulls[7] = false; values[8] = ObjectIdGetDatum(ControlFile->checkPointCopy.nextOid); @@ -205,11 +205,11 @@ pg_control_checkpoint(PG_FUNCTION_ARGS) Datum pg_control_recovery(PG_FUNCTION_ARGS) { - Datum values[5]; - bool nulls[5]; - TupleDesc tupdesc; - HeapTuple htup; - ControlFileData *ControlFile; + Datum values[5]; + bool nulls[5]; + TupleDesc tupdesc; + HeapTuple htup; + ControlFileData *ControlFile; /* * Construct a tuple descriptor for the result row. This must match this @@ -254,11 +254,11 @@ pg_control_recovery(PG_FUNCTION_ARGS) Datum pg_control_init(PG_FUNCTION_ARGS) { - Datum values[13]; - bool nulls[13]; - TupleDesc tupdesc; - HeapTuple htup; - ControlFileData *ControlFile; + Datum values[13]; + bool nulls[13]; + TupleDesc tupdesc; + HeapTuple htup; + ControlFileData *ControlFile; /* * Construct a tuple descriptor for the result row. This must match this diff --git a/src/backend/utils/resowner/resowner.c b/src/backend/utils/resowner/resowner.c index 6856ad0d19f..07075ce06de 100644 --- a/src/backend/utils/resowner/resowner.c +++ b/src/backend/utils/resowner/resowner.c @@ -128,7 +128,7 @@ typedef struct ResourceOwnerData /* We can remember up to MAX_RESOWNER_LOCKS references to local locks. */ int nlocks; /* number of owned locks */ LOCALLOCK *locks[MAX_RESOWNER_LOCKS]; /* list of owned locks */ -} ResourceOwnerData; +} ResourceOwnerData; /***************************************************************************** diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 4cc5be92a2a..7878660055a 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -263,7 +263,7 @@ struct Tuplesortstate int maxTapes; /* number of tapes (Knuth's T) */ int tapeRange; /* maxTapes-1 (Knuth's P) */ MemoryContext sortcontext; /* memory context holding most sort data */ - MemoryContext tuplecontext; /* sub-context of sortcontext for tuple data */ + MemoryContext tuplecontext; /* sub-context of sortcontext for tuple data */ LogicalTapeSet *tapeset; /* logtape.c object for tapes in a temp file */ /* @@ -321,10 +321,10 @@ struct Tuplesortstate /* * Memory for tuples is sometimes allocated in batch, rather than - * incrementally. This implies that incremental memory accounting has been - * abandoned. Currently, this only happens for the final on-the-fly merge - * step. Large batch allocations can store tuples (e.g. IndexTuples) - * without palloc() fragmentation and other overhead. + * incrementally. This implies that incremental memory accounting has + * been abandoned. Currently, this only happens for the final on-the-fly + * merge step. Large batch allocations can store tuples (e.g. + * IndexTuples) without palloc() fragmentation and other overhead. */ bool batchUsed; @@ -337,8 +337,8 @@ struct Tuplesortstate /* * While building initial runs, this is the current output run number - * (starting at RUN_FIRST). Afterwards, it is the number of initial - * runs we made. + * (starting at RUN_FIRST). Afterwards, it is the number of initial runs + * we made. */ int currentRun; @@ -375,9 +375,9 @@ struct Tuplesortstate * just a few large allocations. * * Aside from the general benefits of performing fewer individual retail - * palloc() calls, this also helps make merging more cache efficient, since - * each tape's tuples must naturally be accessed sequentially (in sorted - * order). + * palloc() calls, this also helps make merging more cache efficient, + * since each tape's tuples must naturally be accessed sequentially (in + * sorted order). */ int64 spacePerTape; /* Space (memory) for tuples (not slots) */ char **mergetuples; /* Each tape's memory allocation */ @@ -546,9 +546,9 @@ static void beginmerge(Tuplesortstate *state, bool finalMerge); static void batchmemtuples(Tuplesortstate *state); static void mergebatch(Tuplesortstate *state, int64 spacePerTape); static void mergebatchone(Tuplesortstate *state, int srcTape, - SortTuple *stup, bool *should_free); + SortTuple *stup, bool *should_free); static void mergebatchfreetape(Tuplesortstate *state, int srcTape, - SortTuple *rtup, bool *should_free); + SortTuple *rtup, bool *should_free); static void *mergebatchalloc(Tuplesortstate *state, int tapenum, Size tuplen); static void mergepreread(Tuplesortstate *state); static void mergeprereadone(Tuplesortstate *state, int srcTape); @@ -647,10 +647,10 @@ tuplesort_begin_common(int workMem, bool randomAccess) * Caller tuple (e.g. IndexTuple) memory context. * * A dedicated child content used exclusively for caller passed tuples - * eases memory management. Resetting at key points reduces fragmentation. - * Note that the memtuples array of SortTuples is allocated in the parent - * context, not this context, because there is no need to free memtuples - * early. + * eases memory management. Resetting at key points reduces + * fragmentation. Note that the memtuples array of SortTuples is allocated + * in the parent context, not this context, because there is no need to + * free memtuples early. */ tuplecontext = AllocSetContextCreate(sortcontext, "Caller tuples", @@ -1042,8 +1042,8 @@ tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation, * a pass-by-value datatype could have an abbreviated form that is cheaper * to compare. In a tuple sort, we could support that, because we can * always extract the original datum from the tuple is needed. Here, we - * can't, because a datum sort only stores a single copy of the datum; - * the "tuple" field of each sortTuple is NULL. + * can't, because a datum sort only stores a single copy of the datum; the + * "tuple" field of each sortTuple is NULL. */ state->sortKeys->abbreviate = !typbyval; @@ -1413,8 +1413,7 @@ tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel, * ensure a consistent representation (current tuple was just * handled). It does not matter if some dumped tuples are already * sorted on tape, since serialized tuples lack abbreviated keys - * (TSS_BUILDRUNS state prevents control reaching here in any - * case). + * (TSS_BUILDRUNS state prevents control reaching here in any case). */ for (i = 0; i < state->memtupcount; i++) { @@ -1459,8 +1458,8 @@ tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull) if (isNull || !state->tuples) { /* - * Set datum1 to zeroed representation for NULLs (to be consistent, and - * to support cheap inequality tests for NULL abbreviated keys). + * Set datum1 to zeroed representation for NULLs (to be consistent, + * and to support cheap inequality tests for NULL abbreviated keys). */ stup.datum1 = !isNull ? val : (Datum) 0; stup.isnull1 = isNull; @@ -1498,10 +1497,10 @@ tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull) * * Alter datum1 representation in already-copied tuples, so as to * ensure a consistent representation (current tuple was just - * handled). It does not matter if some dumped tuples are - * already sorted on tape, since serialized tuples lack - * abbreviated keys (TSS_BUILDRUNS state prevents control - * reaching here in any case). + * handled). It does not matter if some dumped tuples are already + * sorted on tape, since serialized tuples lack abbreviated keys + * (TSS_BUILDRUNS state prevents control reaching here in any + * case). */ for (i = 0; i < state->memtupcount; i++) { @@ -1965,11 +1964,11 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward, SortTuple *newtup; /* - * Returned tuple is still counted in our memory space most - * of the time. See mergebatchone() for discussion of why - * caller may occasionally be required to free returned - * tuple, and how preread memory is managed with regard to - * edge cases more generally. + * Returned tuple is still counted in our memory space most of + * the time. See mergebatchone() for discussion of why caller + * may occasionally be required to free returned tuple, and + * how preread memory is managed with regard to edge cases + * more generally. */ *stup = state->memtuples[0]; tuplesort_heap_siftup(state, false); @@ -2269,8 +2268,8 @@ useselection(Tuplesortstate *state) /* * memtupsize might be noticeably higher than memtupcount here in atypical * cases. It seems slightly preferable to not allow recent outliers to - * impact this determination. Note that caller's trace_sort output reports - * memtupcount instead. + * impact this determination. Note that caller's trace_sort output + * reports memtupcount instead. */ if (state->memtupsize <= replacement_sort_tuples) return true; @@ -2349,9 +2348,9 @@ inittapes(Tuplesortstate *state) state->tp_tapenum = (int *) palloc0(maxTapes * sizeof(int)); /* - * Give replacement selection a try based on user setting. There will - * be a switch to a simple hybrid sort-merge strategy after the first - * run (iff we could not output one long run). + * Give replacement selection a try based on user setting. There will be + * a switch to a simple hybrid sort-merge strategy after the first run + * (iff we could not output one long run). */ state->replaceActive = useselection(state); @@ -2372,7 +2371,7 @@ inittapes(Tuplesortstate *state) elog(LOG, "replacement selection will sort %d first run tuples", state->memtupcount); #endif - state->memtupcount = 0; /* make the heap empty */ + state->memtupcount = 0; /* make the heap empty */ for (j = 0; j < ntuples; j++) { @@ -2792,8 +2791,8 @@ beginmerge(Tuplesortstate *state, bool finalMergeBatch) int usedSlots; /* - * Report how effective batchmemtuples() was in balancing - * the number of slots against the need for memory for the + * Report how effective batchmemtuples() was in balancing the + * number of slots against the need for memory for the * underlying tuples (e.g. IndexTuples). The big preread of * all tapes when switching to FINALMERGE state should be * fairly representative of memory utilization during the @@ -2847,9 +2846,9 @@ beginmerge(Tuplesortstate *state, bool finalMergeBatch) static void batchmemtuples(Tuplesortstate *state) { - int64 refund; - int64 availMemLessRefund; - int memtupsize = state->memtupsize; + int64 refund; + int64 availMemLessRefund; + int memtupsize = state->memtupsize; /* For simplicity, assume no memtuples are actually currently counted */ Assert(state->memtupcount == 0); @@ -2867,8 +2866,8 @@ batchmemtuples(Tuplesortstate *state) /* * To establish balanced memory use after refunding palloc overhead, * temporarily have our accounting indicate that we've allocated all - * memory we're allowed to less that refund, and call grow_memtuples() - * to have it increase the number of slots. + * memory we're allowed to less that refund, and call grow_memtuples() to + * have it increase the number of slots. */ state->growmemtuples = true; USEMEM(state, availMemLessRefund); @@ -2880,8 +2879,8 @@ batchmemtuples(Tuplesortstate *state) #ifdef TRACE_SORT if (trace_sort) { - Size OldKb = (memtupsize * sizeof(SortTuple) + 1023) / 1024; - Size NewKb = (state->memtupsize * sizeof(SortTuple) + 1023) / 1024; + Size OldKb = (memtupsize * sizeof(SortTuple) + 1023) / 1024; + Size NewKb = (state->memtupsize * sizeof(SortTuple) + 1023) / 1024; elog(LOG, "grew memtuples %1.2fx from %d (%zu KB) to %d (%zu KB) for final merge", (double) NewKb / (double) OldKb, @@ -2910,7 +2909,7 @@ batchmemtuples(Tuplesortstate *state) static void mergebatch(Tuplesortstate *state, int64 spacePerTape) { - int srcTape; + int srcTape; Assert(state->activeTapes > 0); Assert(state->tuples); @@ -2966,13 +2965,13 @@ mergebatchone(Tuplesortstate *state, int srcTape, SortTuple *rtup, */ if (!state->mergeoverflow[srcTape]) { - Size tupLen; + Size tupLen; /* * Mark tuple buffer range for reuse, but be careful to move final, - * tail tuple to start of space for next run so that it's available - * to caller when stup is returned, and remains available at least - * until the next tuple is requested. + * tail tuple to start of space for next run so that it's available to + * caller when stup is returned, and remains available at least until + * the next tuple is requested. */ tupLen = state->mergecurrent[srcTape] - state->mergetail[srcTape]; state->mergecurrent[srcTape] = state->mergetuples[srcTape]; @@ -3081,9 +3080,9 @@ mergebatchalloc(Tuplesortstate *state, int tapenum, Size tuplen) state->mergetuples[tapenum] + state->spacePerTape) { /* - * Usual case -- caller is returned pointer into its tape's buffer, and - * an offset from that point is recorded as where tape has consumed up - * to for current round of preloading. + * Usual case -- caller is returned pointer into its tape's buffer, + * and an offset from that point is recorded as where tape has + * consumed up to for current round of preloading. */ ret = state->mergetail[tapenum] = state->mergecurrent[tapenum]; state->mergecurrent[tapenum] += reserve_tuplen; @@ -3238,8 +3237,8 @@ dumptuples(Tuplesortstate *state, bool alltuples) if (state->replaceActive) { /* - * Still holding out for a case favorable to replacement selection. - * Still incrementally spilling using heap. + * Still holding out for a case favorable to replacement + * selection. Still incrementally spilling using heap. * * Dump the heap's frontmost entry, and sift up to remove it from * the heap. @@ -3252,17 +3251,15 @@ dumptuples(Tuplesortstate *state, bool alltuples) else { /* - * Once committed to quicksorting runs, never incrementally - * spill + * Once committed to quicksorting runs, never incrementally spill */ dumpbatch(state, alltuples); break; } /* - * If top run number has changed, we've finished the current run - * (this can only be the first run), and will no longer spill - * incrementally. + * If top run number has changed, we've finished the current run (this + * can only be the first run), and will no longer spill incrementally. */ if (state->memtupcount == 0 || state->memtuples[0].tupindex == HEAP_RUN_NEXT) @@ -3280,6 +3277,7 @@ dumptuples(Tuplesortstate *state, bool alltuples) state->currentRun, state->destTape, pg_rusage_show(&state->ru_start)); #endif + /* * Done if heap is empty, which is possible when there is only one * long run. @@ -3334,19 +3332,19 @@ dumpbatch(Tuplesortstate *state, bool alltuples) * remaining tuples are loaded into memory, just before input was * exhausted. * - * In general, short final runs are quite possible. Rather than - * allowing a special case where there was a superfluous - * selectnewtape() call (i.e. a call with no subsequent run actually - * written to destTape), we prefer to write out a 0 tuple run. + * In general, short final runs are quite possible. Rather than allowing + * a special case where there was a superfluous selectnewtape() call (i.e. + * a call with no subsequent run actually written to destTape), we prefer + * to write out a 0 tuple run. * * mergepreread()/mergeprereadone() are prepared for 0 tuple runs, and * will reliably mark the tape inactive for the merge when called from * beginmerge(). This case is therefore similar to the case where * mergeonerun() finds a dummy run for the tape, and so doesn't need to - * merge a run from the tape (or conceptually "merges" the dummy run, - * if you prefer). According to Knuth, Algorithm D "isn't strictly - * optimal" in its method of distribution and dummy run assignment; - * this edge case seems very unlikely to make that appreciably worse. + * merge a run from the tape (or conceptually "merges" the dummy run, if + * you prefer). According to Knuth, Algorithm D "isn't strictly optimal" + * in its method of distribution and dummy run assignment; this edge case + * seems very unlikely to make that appreciably worse. */ Assert(state->status == TSS_BUILDRUNS); @@ -3369,8 +3367,8 @@ dumpbatch(Tuplesortstate *state, bool alltuples) #endif /* - * Sort all tuples accumulated within the allowed amount of memory for this - * run using quicksort + * Sort all tuples accumulated within the allowed amount of memory for + * this run using quicksort */ tuplesort_sort_memtuples(state); @@ -3848,11 +3846,11 @@ readtup_alloc(Tuplesortstate *state, int tapenum, Size tuplen) if (state->batchUsed) { /* - * No USEMEM() call, because during final on-the-fly merge - * accounting is based on tape-private state. ("Overflow" - * allocations are detected as an indication that a new round - * or preloading is required. Preloading marks existing - * contents of tape's batch buffer for reuse.) + * No USEMEM() call, because during final on-the-fly merge accounting + * is based on tape-private state. ("Overflow" allocations are + * detected as an indication that a new round or preloading is + * required. Preloading marks existing contents of tape's batch buffer + * for reuse.) */ return mergebatchalloc(state, tapenum, tuplen); } @@ -3993,8 +3991,7 @@ copytup_heap(Tuplesortstate *state, SortTuple *stup, void *tup) * ensure a consistent representation (current tuple was just * handled). It does not matter if some dumped tuples are already * sorted on tape, since serialized tuples lack abbreviated keys - * (TSS_BUILDRUNS state prevents control reaching here in any - * case). + * (TSS_BUILDRUNS state prevents control reaching here in any case). */ for (i = 0; i < state->memtupcount; i++) { @@ -4238,8 +4235,7 @@ copytup_cluster(Tuplesortstate *state, SortTuple *stup, void *tup) * ensure a consistent representation (current tuple was just * handled). It does not matter if some dumped tuples are already * sorted on tape, since serialized tuples lack abbreviated keys - * (TSS_BUILDRUNS state prevents control reaching here in any - * case). + * (TSS_BUILDRUNS state prevents control reaching here in any case). */ for (i = 0; i < state->memtupcount; i++) { @@ -4544,8 +4540,7 @@ copytup_index(Tuplesortstate *state, SortTuple *stup, void *tup) * ensure a consistent representation (current tuple was just * handled). It does not matter if some dumped tuples are already * sorted on tape, since serialized tuples lack abbreviated keys - * (TSS_BUILDRUNS state prevents control reaching here in any - * case). + * (TSS_BUILDRUNS state prevents control reaching here in any case). */ for (i = 0; i < state->memtupcount; i++) { diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c index f8a2a83b88c..8a1c9932e54 100644 --- a/src/backend/utils/time/snapmgr.c +++ b/src/backend/utils/time/snapmgr.c @@ -78,16 +78,15 @@ typedef struct OldSnapshotControlData * Variables for old snapshot handling are shared among processes and are * only allowed to move forward. */ - slock_t mutex_current; /* protect current_timestamp */ + slock_t mutex_current; /* protect current_timestamp */ int64 current_timestamp; /* latest snapshot timestamp */ - slock_t mutex_latest_xmin; /* protect latest_xmin - * and next_map_update - */ - TransactionId latest_xmin; /* latest snapshot xmin */ - int64 next_map_update; /* latest snapshot valid up to */ - slock_t mutex_threshold; /* protect threshold fields */ + slock_t mutex_latest_xmin; /* protect latest_xmin and + * next_map_update */ + TransactionId latest_xmin; /* latest snapshot xmin */ + int64 next_map_update; /* latest snapshot valid up to */ + slock_t mutex_threshold; /* protect threshold fields */ int64 threshold_timestamp; /* earlier snapshot is old */ - TransactionId threshold_xid; /* earlier xid may be gone */ + TransactionId threshold_xid; /* earlier xid may be gone */ /* * Keep one xid per minute for old snapshot error handling. @@ -117,11 +116,11 @@ typedef struct OldSnapshotControlData * * Persistence is not needed. */ - int head_offset; /* subscript of oldest tracked time */ - int64 head_timestamp; /* time corresponding to head xid */ - int count_used; /* how many slots are in use */ + int head_offset; /* subscript of oldest tracked time */ + int64 head_timestamp; /* time corresponding to head xid */ + int count_used; /* how many slots are in use */ TransactionId xid_by_minute[FLEXIBLE_ARRAY_MEMBER]; -} OldSnapshotControlData; +} OldSnapshotControlData; static volatile OldSnapshotControlData *oldSnapshotControl; @@ -709,8 +708,8 @@ UpdateActiveSnapshotCommandId(void) /* * Don't allow modification of the active snapshot during parallel - * operation. We share the snapshot to worker backends at the beginning of - * parallel operation, so any change to the snapshot can lead to + * operation. We share the snapshot to worker backends at the beginning + * of parallel operation, so any change to the snapshot can lead to * inconsistencies. We have other defenses against * CommandCounterIncrement, but there are a few places that call this * directly, so we put an additional guard here. @@ -1634,7 +1633,7 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin, } ts = AlignTimestampToMinuteBoundary(ts) - - (old_snapshot_threshold * USECS_PER_MINUTE); + - (old_snapshot_threshold * USECS_PER_MINUTE); /* Check for fast exit without LW locking. */ SpinLockAcquire(&oldSnapshotControl->mutex_threshold); @@ -1660,14 +1659,14 @@ TransactionIdLimitedForOldSnapshots(TransactionId recentXmin, if (oldSnapshotControl->count_used > 0 && ts >= oldSnapshotControl->head_timestamp) { - int offset; + int offset; offset = ((ts - oldSnapshotControl->head_timestamp) / USECS_PER_MINUTE); if (offset > oldSnapshotControl->count_used - 1) offset = oldSnapshotControl->count_used - 1; offset = (oldSnapshotControl->head_offset + offset) - % OLD_SNAPSHOT_TIME_MAP_ENTRIES; + % OLD_SNAPSHOT_TIME_MAP_ENTRIES; xlimit = oldSnapshotControl->xid_by_minute[offset]; if (NormalTransactionIdFollows(xlimit, recentXmin)) @@ -1715,8 +1714,8 @@ MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) ts = AlignTimestampToMinuteBoundary(whenTaken); /* - * Keep track of the latest xmin seen by any process. Update mapping - * with a new value when we have crossed a bucket boundary. + * Keep track of the latest xmin seen by any process. Update mapping with + * a new value when we have crossed a bucket boundary. */ SpinLockAcquire(&oldSnapshotControl->mutex_latest_xmin); latest_xmin = oldSnapshotControl->latest_xmin; @@ -1747,7 +1746,7 @@ MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) if (whenTaken < 0) { elog(DEBUG1, - "MaintainOldSnapshotTimeMapping called with negative whenTaken = %ld", + "MaintainOldSnapshotTimeMapping called with negative whenTaken = %ld", (long) whenTaken); return; } @@ -1789,10 +1788,10 @@ MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) * USECS_PER_MINUTE))) { /* existing mapping; advance xid if possible */ - int bucket = (oldSnapshotControl->head_offset - + ((ts - oldSnapshotControl->head_timestamp) - / USECS_PER_MINUTE)) - % OLD_SNAPSHOT_TIME_MAP_ENTRIES; + int bucket = (oldSnapshotControl->head_offset + + ((ts - oldSnapshotControl->head_timestamp) + / USECS_PER_MINUTE)) + % OLD_SNAPSHOT_TIME_MAP_ENTRIES; if (TransactionIdPrecedes(oldSnapshotControl->xid_by_minute[bucket], xmin)) oldSnapshotControl->xid_by_minute[bucket] = xmin; @@ -1800,8 +1799,8 @@ MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) else { /* We need a new bucket, but it might not be the very next one. */ - int advance = ((ts - oldSnapshotControl->head_timestamp) - / USECS_PER_MINUTE); + int advance = ((ts - oldSnapshotControl->head_timestamp) + / USECS_PER_MINUTE); oldSnapshotControl->head_timestamp = ts; @@ -1815,14 +1814,14 @@ MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) else { /* Store the new value in one or more buckets. */ - int i; + int i; for (i = 0; i < advance; i++) { if (oldSnapshotControl->count_used == OLD_SNAPSHOT_TIME_MAP_ENTRIES) { /* Map full and new value replaces old head. */ - int old_head = oldSnapshotControl->head_offset; + int old_head = oldSnapshotControl->head_offset; if (old_head == (OLD_SNAPSHOT_TIME_MAP_ENTRIES - 1)) oldSnapshotControl->head_offset = 0; @@ -1833,9 +1832,9 @@ MaintainOldSnapshotTimeMapping(int64 whenTaken, TransactionId xmin) else { /* Extend map to unused entry. */ - int new_tail = (oldSnapshotControl->head_offset - + oldSnapshotControl->count_used) - % OLD_SNAPSHOT_TIME_MAP_ENTRIES; + int new_tail = (oldSnapshotControl->head_offset + + oldSnapshotControl->count_used) + % OLD_SNAPSHOT_TIME_MAP_ENTRIES; oldSnapshotControl->count_used++; oldSnapshotControl->xid_by_minute[new_tail] = xmin; |