On Thu, 2025-08-14 at 11:23 +1000, Peter Smith wrote: > Here are the latest v18* patches. >
Hi Peter! I've reworked my recent patch [1] so it is now based on v18 and is divided into several simpler patches. Here they are plus one additional patch. 0001-Fixed-comment-and-guard-name-in-vci_pg_copy.h.patch Looks like vci_pg_copy.h was renamed from vci_numeric.h but file name comment and define guard name were not updated. Fixed it. 0002-Removed-vci_set_merge_and_copy_trans_funcs.patch Found that vci_set_merge_and_copy_trans_funcs() is not used anywhere, removed it alogn with the code that was only called inside it. trans_funcs_table[] now only contains single transfn_oid field, others (unused) are removed. 0003-Replaced-linear-search-by-switch-case.patch Replaced linear search inside trans_funcs_table array to more optimal switch-case. 0004-Removed-worker-name-check-in-lock.c.patch This is one I'm not sure about. Found that changes in Postgres core lock.c file check for "backend=" substring in background worker name. There is also a comment in vci_ros_daemon.c mentioning bgw_name checks of LockAquire(). Names don't match however. So as far as I understand the check for "backend=" in name is always false since no code in VCI sets bgw_name to something similar. This is either forgotten feature that can be easily fixed by removing bgw_name checks, either some bug, either my misunderstanding. For the first case, here is a patch that removes bgw_name checks in lock.c. It makes core patch a bit smaller and not touching lock.c at all (Yay!). [1] https://www.postgresql.org/message-id/8beac6e8a01971b22ccf0f2e2a8eb12a78e5a7ac.camel%40postgrespro.ru -- Regards, Timur Magomedov
From e045a80d50e2a0ad211634ff6dfcf5f0f46de36b Mon Sep 17 00:00:00 2001 From: Timur Magomedov <t.magome...@postgrespro.ru> Date: Thu, 14 Aug 2025 20:09:37 +0300 Subject: [PATCH 1/4] Fixed comment and guard name in vci_pg_copy.h --- contrib/vci/include/vci_pg_copy.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/vci/include/vci_pg_copy.h b/contrib/vci/include/vci_pg_copy.h index 5a1ec07009a..068162f5c16 100644 --- a/contrib/vci/include/vci_pg_copy.h +++ b/contrib/vci/include/vci_pg_copy.h @@ -1,18 +1,18 @@ /*------------------------------------------------------------------------- * - * vci_numeric.h + * vci_pg_copy.h * Some useful functions of PostgreSQL * * Portions Copyright (c) 2025, PostgreSQL Global Development Group * * IDENTIFICATION - * contrib/vci/include/vci_numeric.h + * contrib/vci/include/vci_pg_copy.h * *------------------------------------------------------------------------- */ -#ifndef VCI_NUMERIC_H -#define VCI_NUMERIC_H +#ifndef VCI_PG_COPY_H +#define VCI_PG_COPY_H #include "datatype/timestamp.h" @@ -74,4 +74,4 @@ interval_cmp_value(const Interval *interval) return span; } -#endif /* #ifndef VCI_NUMERIC_H */ +#endif /* #ifndef VCI_PG_COPY_H */ -- 2.43.0
From 93ab6c4cad577bb92ccdb4e4a21d1bb83da5b3fa Mon Sep 17 00:00:00 2001 From: Timur Magomedov <t.magome...@postgrespro.ru> Date: Fri, 15 Aug 2025 14:48:54 +0300 Subject: [PATCH 2/4] Removed vci_set_merge_and_copy_trans_funcs() The function was unused. Some code that only was used in this function was removed also. --- contrib/vci/executor/vci_aggmergetranstype.c | 374 +------------------ contrib/vci/include/postgresql_copy.h | 57 --- contrib/vci/include/vci_executor.h | 11 - contrib/vci/include/vci_pg_copy.h | 19 - src/tools/pgindent/typedefs.list | 3 - 5 files changed, 15 insertions(+), 449 deletions(-) diff --git a/contrib/vci/executor/vci_aggmergetranstype.c b/contrib/vci/executor/vci_aggmergetranstype.c index 8f224e1a470..644c5a6fe9c 100644 --- a/contrib/vci/executor/vci_aggmergetranstype.c +++ b/contrib/vci/executor/vci_aggmergetranstype.c @@ -38,30 +38,6 @@ #include "postgresql_copy.h" -static Datum merge_intX_accum(PG_FUNCTION_ARGS); -static Datum merge_floatX_accum(PG_FUNCTION_ARGS); -static Datum merge_interval_avg_accum(PG_FUNCTION_ARGS); - -static Datum copy_numeric_agg_state(Datum src, bool typByVal, int typLen); -static Datum copy_numeric_avg_agg_state(Datum src, bool typByVal, int typLen); -static Datum copy_poly_num_agg_state(Datum src, bool typByVal, int typLen); -static Datum copy_poly_avg_num_agg_state(Datum src, bool typByVal, int typLen); - -/** - * If Transition data is INTERNALOID, an enum indicating its type - */ -typedef enum vci_aggtranstype_kind -{ - VCI_AGG_NOT_INTERNAL, /* not INTERNALOID */ - VCI_AGG_NUMERIC_AGG_STATE, /* INTERNALOID (use NumericAggState struct) */ - VCI_AGG_POLY_NUM_AGG_STATE, /* INTERNALOID (use PolyNumAggState struct) */ - VCI_AGG_POLY_AVG_NUM_AGG_STATE, /* INTERNALOID (use PolyNumAggState - * without sumx2 struct) */ - VCI_AGG_AVG_NUMERIC_AGG_STATE, /* INTERNALOID (use NumericAggState - * without sumx2 struct) */ - VCI_AGG_ARRAY_BUILD_STATE, /* INTERNALOID (use ArrayBuildState struct) */ -} vci_aggtranstype_kind; - /** * Record information necessary for parallel aggregation for each transition function */ @@ -69,41 +45,22 @@ static struct { int transfn_oid; /* Transition function's funcoid. Array is * sorted in ascending order */ - Oid transtype; /* Transition data type */ - PGFunction merge_trans; /* Function pointer set required for parallel - * aggregation for each transfn_oid */ - vci_aggtranstype_kind kind; /* If transtype is INTERNALOID, its details */ } trans_funcs_table[] = { - {F_FLOAT4_ACCUM, 1022, merge_floatX_accum, VCI_AGG_NOT_INTERNAL}, /* 208 */ - {F_FLOAT8_ACCUM, 1022, merge_floatX_accum, VCI_AGG_NOT_INTERNAL}, /* 222 */ - {F_INT8INC, 20, int8pl, VCI_AGG_NOT_INTERNAL}, /* 1219 */ - {F_NUMERIC_ACCUM, 2281, numeric_combine, VCI_AGG_NUMERIC_AGG_STATE}, /* 1833 */ - {F_INT2_ACCUM, 2281, numeric_poly_combine, VCI_AGG_POLY_NUM_AGG_STATE}, /* 1834 */ - {F_INT4_ACCUM, 2281, numeric_poly_combine, VCI_AGG_POLY_NUM_AGG_STATE}, /* 1835 */ - {F_INT8_ACCUM, 2281, numeric_combine, VCI_AGG_NUMERIC_AGG_STATE}, /* 1836 */ - {F_INT2_SUM, 20, int8pl, VCI_AGG_NOT_INTERNAL}, /* 1840 */ - {F_INT4_SUM, 20, int8pl, VCI_AGG_NOT_INTERNAL}, /* 1841 */ - {F_INT2_AVG_ACCUM, 1016, merge_intX_accum, VCI_AGG_NOT_INTERNAL}, /* 1962 */ - {F_INT4_AVG_ACCUM, 1016, merge_intX_accum, VCI_AGG_NOT_INTERNAL}, /* 1963 */ - {F_INT8_AVG_ACCUM, 2281, int8_avg_combine, VCI_AGG_POLY_AVG_NUM_AGG_STATE}, /* 2746 */ - {F_INT8INC_ANY, 20, int8pl, VCI_AGG_NOT_INTERNAL}, /* 2804 */ - {F_NUMERIC_AVG_ACCUM, 2281, numeric_avg_combine, VCI_AGG_AVG_NUMERIC_AGG_STATE}, /* 2858 */ - {F_INTERVAL_AVG_COMBINE, 2281, merge_interval_avg_accum, VCI_AGG_NOT_INTERNAL}, /* 3325 */ -}; - -/** - * If INTEROID, copy functions, SEND function, RECV function - */ -static vci_agg_trans_copy_funcs trans_internal_type_funcs_table[] = { - {datumCopy, NULL, NULL}, /* VCI_AGG_NOT_INTERNAL */ - {copy_numeric_agg_state, numeric_serialize, numeric_deserialize}, /* VCI_AGG_NUMERIC_AGG_STATE - * */ - {copy_poly_num_agg_state, numeric_poly_serialize, numeric_poly_deserialize}, /* VCI_AGG_NUMERIC_POLY_AGG_STATE - * */ - {copy_poly_avg_num_agg_state, int8_avg_serialize, int8_avg_deserialize}, /* VCI_AGG_POLY_AVG_NUM_AGG_STATE - * */ - {copy_numeric_avg_agg_state, numeric_avg_serialize, numeric_avg_deserialize}, /* VCI_AGG_AVG_NUMERIC_AGG_STATE - * */ + {F_FLOAT4_ACCUM}, /* 208 */ + {F_FLOAT8_ACCUM}, /* 222 */ + {F_INT8INC}, /* 1219 */ + {F_NUMERIC_ACCUM}, /* 1833 */ + {F_INT2_ACCUM}, /* 1834 */ + {F_INT4_ACCUM}, /* 1835 */ + {F_INT8_ACCUM}, /* 1836 */ + {F_INT2_SUM}, /* 1840 */ + {F_INT4_SUM}, /* 1841 */ + {F_INT2_AVG_ACCUM}, /* 1962 */ + {F_INT4_AVG_ACCUM}, /* 1963 */ + {F_INT8_AVG_ACCUM}, /* 2746 */ + {F_INT8INC_ANY}, /* 2804 */ + {F_NUMERIC_AVG_ACCUM}, /* 2858 */ + {F_INTERVAL_AVG_COMBINE}, /* 3325 */ }; /** @@ -187,304 +144,3 @@ vci_is_supported_aggregation(Aggref *aggref) return ret; } - -/** - * Obtain the merge and copy-related functions for the transition internal state - * generated by the given transition function. - * - * @param[in] transfn_oid specify a transition function - * @param[out] merge_trans_p set the merge function - * @param[out] copy_trans_p set the copy function - * @param[out] send_trans_p set the send function - * @param[out] recv_trans_p set the recv function - * - * @retval true Found the copy and merge function - * @retval false Not exist - * - * @note Output parameters are set only if the return value is true. - */ -bool -vci_set_merge_and_copy_trans_funcs(Oid transfn_oid, PGFunction *merge_trans_p, VciCopyDatumFunc *copy_trans_p, PGFunction *send_trans_p, PGFunction *recv_trans_p) -{ - int i; - - for (i = 0; i < lengthof(trans_funcs_table); i++) - { - if (transfn_oid == trans_funcs_table[i].transfn_oid) - { - vci_aggtranstype_kind kind = trans_funcs_table[i].kind; - - *merge_trans_p = trans_funcs_table[i].merge_trans; - *copy_trans_p = trans_internal_type_funcs_table[kind].copy_trans; - *send_trans_p = trans_internal_type_funcs_table[kind].send_trans; - *recv_trans_p = trans_internal_type_funcs_table[kind].recv_trans; - - return true; - } - } - - return false; -} - -static Datum -merge_intX_accum(PG_FUNCTION_ARGS) -{ - ArrayType *transarray0 = PG_GETARG_ARRAYTYPE_P(0); - ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(1); - Int8TransTypeData *transdata0; - Int8TransTypeData *transdata1; - - transdata0 = (Int8TransTypeData *) ARR_DATA_PTR(transarray0); - transdata1 = (Int8TransTypeData *) ARR_DATA_PTR(transarray1); - - transdata0->count += transdata1->count; - transdata0->sum += transdata1->sum; - - PG_RETURN_ARRAYTYPE_P(transarray0); -} - -static Datum -merge_floatX_accum(PG_FUNCTION_ARGS) -{ - ArrayType *transarray1 = PG_GETARG_ARRAYTYPE_P(0); - ArrayType *transarray2 = PG_GETARG_ARRAYTYPE_P(1); - float8 *transvalues1; - float8 *transvalues2; - float8 N1, - Sx1, - Sxx1, - N2, - Sx2, - Sxx2, - tmp, - N, - Sx, - Sxx; - - transvalues1 = check_float8_array(transarray1, "merge_floatX_accum", 3); - transvalues2 = check_float8_array(transarray2, "merge_floatX_accum", 3); - - N1 = transvalues1[0]; - Sx1 = transvalues1[1]; - Sxx1 = transvalues1[2]; - - N2 = transvalues2[0]; - Sx2 = transvalues2[1]; - Sxx2 = transvalues2[2]; - - /*-------------------- - * The transition values combine using a generalization of the - * Youngs-Cramer algorithm as follows: - * - * N = N1 + N2 - * Sx = Sx1 + Sx2 - * Sxx = Sxx1 + Sxx2 + N1 * N2 * (Sx1/N1 - Sx2/N2)^2 / N; - * - * It's worth handling the special cases N1 = 0 and N2 = 0 separately - * since those cases are trivial, and we then don't need to worry about - * division-by-zero errors in the general case. - *-------------------- - */ - if (N1 == 0.0) - { - N = N2; - Sx = Sx2; - Sxx = Sxx2; - } - else if (N2 == 0.0) - { - N = N1; - Sx = Sx1; - Sxx = Sxx1; - } - else - { - N = N1 + N2; - /* Sx = float8_pl(Sx1, Sx2); */ - Sx = Sx1 + Sx2; - CHECKFLOATVAL(Sx, isinf(Sx1) || isinf(Sx2), true); - tmp = Sx1 / N1 - Sx2 / N2; - Sxx = Sxx1 + Sxx2 + N1 * N2 * tmp * tmp / N; - CHECKFLOATVAL(Sxx, isinf(Sxx1) || isinf(Sxx2), true); - } - - transvalues1[0] = N; - transvalues1[1] = Sx; - transvalues1[2] = Sxx; - - PG_RETURN_ARRAYTYPE_P(transarray1); -} - -static Datum -merge_interval_avg_accum(PG_FUNCTION_ARGS) -{ - IntervalAggState *state1; - IntervalAggState *state2; - - state1 = PG_ARGISNULL(0) ? NULL : (IntervalAggState *) PG_GETARG_POINTER(0); - state2 = PG_ARGISNULL(1) ? NULL : (IntervalAggState *) PG_GETARG_POINTER(1); - - /* Create the state data on the first call */ - if (state2 == NULL) - PG_RETURN_POINTER(state1); - - if (state1 == NULL) - { - state1 = makeIntervalAggState(fcinfo); - - state1->N = state2->N; - state1->pInfcount = state2->pInfcount; - state1->nInfcount = state2->nInfcount; - - state1->sumX.day = state2->sumX.day; - state1->sumX.month = state2->sumX.month; - state1->sumX.time = state2->sumX.time; - - PG_RETURN_POINTER(state1); - } - - state1->N += state2->N; - state1->pInfcount += state2->pInfcount; - state1->nInfcount += state2->nInfcount; - - /* Accumulate finite interval values, if any. */ - if (state2->N > 0) - finite_interval_pl(&state1->sumX, &state2->sumX, &state1->sumX); - - PG_RETURN_POINTER(state1); -} - -/*****************************************************************************/ -/* numeric */ -/*****************************************************************************/ - -/* - * Copy an accumulator's state. - * - * 'dst' is assumed to be uninitialized beforehand. No attempt is made at - * freeing old values. - * - * copied from src/backend/utils/adt/numeric.c - */ -static void -accum_sum_copy(NumericSumAccum *dst, NumericSumAccum *src) -{ - dst->pos_digits = palloc0(src->ndigits * sizeof(int32)); - dst->neg_digits = palloc0(src->ndigits * sizeof(int32)); - - memcpy(dst->pos_digits, src->pos_digits, src->ndigits * sizeof(int32)); - memcpy(dst->neg_digits, src->neg_digits, src->ndigits * sizeof(int32)); - dst->num_uncarried = src->num_uncarried; - dst->ndigits = src->ndigits; - dst->weight = src->weight; - dst->dscale = src->dscale; -} - -static Datum -copy_numeric_agg_state(Datum src, bool typByVal, int typLen) -{ - NumericAggState *from, - *to; - - from = (NumericAggState *) DatumGetPointer(src); - - if (from == NULL) - return (Datum) NULL; - - to = palloc0(sizeof(NumericAggState)); - - to->calcSumX2 = from->calcSumX2; - to->agg_context = CurrentMemoryContext; - to->N = from->N; - to->NaNcount = from->NaNcount; - to->pInfcount = from->pInfcount; - to->nInfcount = from->nInfcount; - to->maxScale = from->maxScale; - to->maxScaleCount = from->maxScaleCount; - - accum_sum_copy(&to->sumX, &from->sumX); - accum_sum_copy(&to->sumX2, &from->sumX2); - - return PointerGetDatum(to); -} - -static Datum -copy_numeric_avg_agg_state(Datum src, bool typByVal, int typLen) -{ - NumericAggState *from, - *to; - - from = (NumericAggState *) DatumGetPointer(src); - - if (from == NULL) - return (Datum) NULL; - - to = palloc0(sizeof(NumericAggState)); - - to->calcSumX2 = from->calcSumX2; - to->agg_context = CurrentMemoryContext; - to->N = from->N; - to->NaNcount = from->NaNcount; - to->pInfcount = from->pInfcount; - to->nInfcount = from->nInfcount; - to->maxScale = from->maxScale; - to->maxScaleCount = from->maxScaleCount; - - accum_sum_copy(&to->sumX, &from->sumX); - - return PointerGetDatum(to); -} - -static Datum -copy_poly_num_agg_state(Datum src, bool typByVal, int typLen) -{ - PolyNumAggState *from, - *to; - - from = (PolyNumAggState *) DatumGetPointer(src); - - if (from == NULL) - return (Datum) NULL; - - to = palloc0(sizeof(PolyNumAggState)); - - to->calcSumX2 = from->calcSumX2; - to->N = from->N; - -#ifdef HAVE_INT128 - to->sumX = from->sumX; - to->sumX2 = from->sumX2; -#else - to->agg_context = CurrentMemoryContext; - accum_sum_copy(&to->sumX, &from->sumX); - accum_sum_copy(&to->sumX2, &from->sumX2); -#endif - - return PointerGetDatum(to); -} - -static Datum -copy_poly_avg_num_agg_state(Datum src, bool typByVal, int typLen) -{ - PolyNumAggState *from, - *to; - - from = (PolyNumAggState *) DatumGetPointer(src); - - if (from == NULL) - return (Datum) NULL; - - to = palloc0(sizeof(PolyNumAggState)); - - to->calcSumX2 = from->calcSumX2; - to->N = from->N; - -#ifdef HAVE_INT128 - to->sumX = from->sumX; -#else - to->agg_context = CurrentMemoryContext; - accum_sum_copy(&to->sumX, &from->sumX); -#endif - - return PointerGetDatum(to); -} diff --git a/contrib/vci/include/postgresql_copy.h b/contrib/vci/include/postgresql_copy.h index a5c1efd9f90..960776a7fc5 100644 --- a/contrib/vci/include/postgresql_copy.h +++ b/contrib/vci/include/postgresql_copy.h @@ -62,69 +62,12 @@ check_float8_array(ArrayType *transarray, const char *caller, int n) return (float8 *) ARR_DATA_PTR(transarray); } -/* - * src/backend/utils/adt/numeric.c - */ -typedef struct NumericSumAccum -{ - int ndigits; - int weight; - int dscale; - int num_uncarried; - bool have_carry_space; - int32 *pos_digits; - int32 *neg_digits; -} NumericSumAccum; - -typedef struct NumericAggState -{ - bool calcSumX2; /* if true, calculate sumX2 */ - MemoryContext agg_context; /* context we're calculating in */ - int64 N; /* count of processed numbers */ - NumericSumAccum sumX; /* sum of processed numbers */ - NumericSumAccum sumX2; /* sum of squares of processed numbers */ - int maxScale; /* maximum scale seen so far */ - int64 maxScaleCount; /* number of values seen with maximum scale */ - /* These counts are *not* included in N! Use NA_TOTAL_COUNT() as needed */ - int64 NaNcount; /* count of NaN values */ - int64 pInfcount; /* count of +Inf values */ - int64 nInfcount; /* count of -Inf values */ -} NumericAggState; - typedef struct Int8TransTypeData { int64 count; int64 sum; } Int8TransTypeData; -/* - * Integer data types in general use Numeric accumulators to share code - * and avoid risk of overflow. - * - * However for performance reasons optimized special-purpose accumulator - * routines are used when possible. - * - * On platforms with 128-bit integer support, the 128-bit routines will be - * used when sum(X) or sum(X*X) fit into 128-bit. - * - * For 16 and 32 bit inputs, the N and sum(X) fit into 64-bit so the 64-bit - * accumulators will be used for SUM and AVG of these data types. - */ - -#ifdef HAVE_INT128 -typedef struct Int128AggState -{ - bool calcSumX2; /* if true, calculate sumX2 */ - int64 N; /* count of processed numbers */ - int128 sumX; /* sum of processed numbers */ - int128 sumX2; /* sum of squares of processed numbers */ -} Int128AggState; - -typedef Int128AggState PolyNumAggState; -#else -typedef NumericAggState PolyNumAggState; -#endif - #ifdef VCI_USE_CMP_FUNC /* * interval_relop - is interval1 relop interval2 diff --git a/contrib/vci/include/vci_executor.h b/contrib/vci/include/vci_executor.h index b46b58d88e3..93e15fd0c3d 100644 --- a/contrib/vci/include/vci_executor.h +++ b/contrib/vci/include/vci_executor.h @@ -847,18 +847,7 @@ extern void vci_advance_aggregates(VciAggState *aggstate, VciAggStatePerGroup pe */ typedef Datum (*VciCopyDatumFunc) (Datum, bool, int); -/** - * Datastruct for passing a set of copy, SEND, RECV functions to aggregate operation - */ -typedef struct vci_agg_trans_copy_funcs -{ - VciCopyDatumFunc copy_trans; - PGFunction send_trans; - PGFunction recv_trans; -} vci_agg_trans_copy_funcs; - extern bool vci_is_supported_aggregation(Aggref *aggref); -extern bool vci_set_merge_and_copy_trans_funcs(Oid transfn_oid, PGFunction *merge_trans_p, VciCopyDatumFunc *copy_trans_p, PGFunction *send_trans_p, PGFunction *recv_trans_p); /* ---------------- * vci_gather.c diff --git a/contrib/vci/include/vci_pg_copy.h b/contrib/vci/include/vci_pg_copy.h index 068162f5c16..800853b847a 100644 --- a/contrib/vci/include/vci_pg_copy.h +++ b/contrib/vci/include/vci_pg_copy.h @@ -55,23 +55,4 @@ typedef struct NumericVar NumericDigit *digits; /* base-NBASE digits */ } NumericVar; -/* taken from src/backend/utils/adt/timestamp.c */ -static inline TimeOffset -interval_cmp_value(const Interval *interval) -{ - TimeOffset span; - - span = interval->time; - -#ifdef HAVE_INT64_TIMESTAMP - span += interval->month * INT64CONST(30) * USECS_PER_DAY; - span += interval->day * INT64CONST(24) * USECS_PER_HOUR; -#else - span += interval->month * ((double) DAYS_PER_MONTH * SECS_PER_DAY); - span += interval->day * ((double) HOURS_PER_DAY * SECS_PER_HOUR); -#endif - - return span; -} - #endif /* #ifndef VCI_PG_COPY_H */ diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index a62ab1fcf55..78871057bce 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -2282,7 +2282,6 @@ PlannerParamItem Point Pointer PolicyInfo -PolyNumAggState Pool PopulateArrayContext PopulateArrayState @@ -4445,7 +4444,6 @@ vci_initexpr_t vci_topmost_plan_cb_t vci_mutator_t VciCopyDatumFunc -vci_agg_trans_copy_funcs vci_CSQueryContextData vci_CSQueryContext vci_seq_scan_buffer_t @@ -4471,7 +4469,6 @@ vcis_tidcrid_pair_item_t vcis_tidcrid_pair_list_t vci_TidCridUpdateListContext vci_TidCridRelations -vci_aggtranstype_kind AggrefTransInfo int8_t int16_t -- 2.43.0
From 700a932afdc4787df52e2b30dee7b5bf278f2441 Mon Sep 17 00:00:00 2001 From: Timur Magomedov <t.magome...@postgrespro.ru> Date: Fri, 15 Aug 2025 14:53:51 +0300 Subject: [PATCH 3/4] Replaced linear search by switch-case Switch-case is usually optimized by compilers into optimal binary search. --- contrib/vci/executor/vci_aggmergetranstype.c | 49 +++++++------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/contrib/vci/executor/vci_aggmergetranstype.c b/contrib/vci/executor/vci_aggmergetranstype.c index 644c5a6fe9c..61a00a6b8da 100644 --- a/contrib/vci/executor/vci_aggmergetranstype.c +++ b/contrib/vci/executor/vci_aggmergetranstype.c @@ -38,31 +38,6 @@ #include "postgresql_copy.h" -/** - * Record information necessary for parallel aggregation for each transition function - */ -static struct -{ - int transfn_oid; /* Transition function's funcoid. Array is - * sorted in ascending order */ -} trans_funcs_table[] = { - {F_FLOAT4_ACCUM}, /* 208 */ - {F_FLOAT8_ACCUM}, /* 222 */ - {F_INT8INC}, /* 1219 */ - {F_NUMERIC_ACCUM}, /* 1833 */ - {F_INT2_ACCUM}, /* 1834 */ - {F_INT4_ACCUM}, /* 1835 */ - {F_INT8_ACCUM}, /* 1836 */ - {F_INT2_SUM}, /* 1840 */ - {F_INT4_SUM}, /* 1841 */ - {F_INT2_AVG_ACCUM}, /* 1962 */ - {F_INT4_AVG_ACCUM}, /* 1963 */ - {F_INT8_AVG_ACCUM}, /* 2746 */ - {F_INT8INC_ANY}, /* 2804 */ - {F_NUMERIC_AVG_ACCUM}, /* 2858 */ - {F_INTERVAL_AVG_COMBINE}, /* 3325 */ -}; - /** * Determine if the given aggregation function is a type that can be supported by VCI * @@ -125,15 +100,27 @@ vci_is_supported_aggregation(Aggref *aggref) } else { - int i; - - for (i = 0; i < lengthof(trans_funcs_table); i++) + switch (transfn_oid) { - if (transfn_oid == trans_funcs_table[i].transfn_oid) - { + case F_FLOAT4_ACCUM: + case F_FLOAT8_ACCUM: + case F_INT8INC: + case F_NUMERIC_ACCUM: + case F_INT2_ACCUM: + case F_INT4_ACCUM: + case F_INT8_ACCUM: + case F_INT2_SUM: + case F_INT4_SUM: + case F_INT2_AVG_ACCUM: + case F_INT4_AVG_ACCUM: + case F_INT8_AVG_ACCUM: + case F_INT8INC_ANY: + case F_NUMERIC_AVG_ACCUM: + case F_INTERVAL_AVG_COMBINE: ret = true; break; - } + default: + break; } } -- 2.43.0
From 74a968a3a9b52ec061957d00181aaaef1422a5eb Mon Sep 17 00:00:00 2001 From: Timur Magomedov <t.magome...@postgrespro.ru> Date: Fri, 15 Aug 2025 16:11:52 +0300 Subject: [PATCH 4/4] Removed worker name check in lock.c --- contrib/vci/storage/vci_ros_daemon.c | 2 -- src/backend/storage/lmgr/lock.c | 26 ++------------------------ 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/contrib/vci/storage/vci_ros_daemon.c b/contrib/vci/storage/vci_ros_daemon.c index 88526bf75e9..e82bf3950bc 100644 --- a/contrib/vci/storage/vci_ros_daemon.c +++ b/contrib/vci/storage/vci_ros_daemon.c @@ -91,8 +91,6 @@ static bool TryToOpenVCIRelations(Oid indexOid, LOCKMODE heapLock, LOCKMODE inde static void CheckRosControlWorkerCancel(void); static void callback_on_exit_worker(int code, Datum arg); -/* BGW_MAXREN = 64 */ -/* If the ROS control worker name is changed then update the bgw_name check in LockAcquire() too.*/ const char VCI_ROS_CONTROL_DAEMON_NAME[BGW_MAXLEN] = "vci:ROS control daemon"; const char VCI_ROS_CONTROL_WORKER_NAME_TEMP[BGW_MAXLEN] = "vci:ROS control worker(slot=%d)"; const char VCI_ROS_CONTROL_WORKER_TYPE[BGW_MAXLEN] = "vci:ROS control worker"; diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index c125b8784f4..f8c88147160 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -39,8 +39,6 @@ #include "access/xlogutils.h" #include "miscadmin.h" #include "pg_trace.h" -#include "pgstat.h" -#include "postmaster/bgworker.h" #include "storage/lmgr.h" #include "storage/proc.h" #include "storage/procarray.h" @@ -812,18 +810,8 @@ LockAcquire(const LOCKTAG *locktag, bool sessionLock, bool dontWait) { - /* - * Don't lock for VCI parallel workers and other type of workers should go - * in normal flow, In case if there is any change in background worker - * name for VCI parallel workers, the following code also needs an update. - * FIXME: Try to use the community parallelism code, so that we don't need - * our own VCI parallel infrastructure. - */ - if (AmBackgroundWorkerProcess() && strstr(MyBgworkerEntry->bgw_name, "backend=")) - return LOCKACQUIRE_OK; - else - return LockAcquireExtended(locktag, lockmode, sessionLock, dontWait, - true, NULL, false); + return LockAcquireExtended(locktag, lockmode, sessionLock, dontWait, + true, NULL, false); } /* @@ -2119,16 +2107,6 @@ LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock) */ if (!locallock || locallock->nLocks <= 0) { - /* - * Don't lock for VCI parallel workers and other type of workers - * should go in normal flow, In case if there is any change in - * background worker name for VCI parallel workers, the following code - * also needs an update. FIXME: Try to use the community parallelism - * code, so that we don't need our own VCI parallel infrastructure. - */ - if (AmBackgroundWorkerProcess() && strstr(MyBgworkerEntry->bgw_name, "backend=")) - return true; - elog(WARNING, "you don't own a lock of type %s", lockMethodTable->lockModeNames[lockmode]); return false; -- 2.43.0