From 00910dee16b175673dc006909978a28b4ff7084a Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov <36882414+akuzm@users.noreply.github.com> Date: Tue, 22 Oct 2024 19:38:34 +0300 Subject: [PATCH] cleanup --- .../function/agg_vector_validity_helper.c | 40 +++++-------------- .../function/float48_accum_single.c | 30 +++++--------- .../vector_agg/function/int128_accum_single.c | 6 +-- .../function/int24_avg_accum_single.c | 6 +-- .../vector_agg/function/int24_sum_single.c | 6 +-- .../function/minmax_arithmetic_single.c | 6 +-- .../vector_agg/function/sum_float_single.c | 10 ++--- 7 files changed, 37 insertions(+), 67 deletions(-) diff --git a/tsl/src/nodes/vector_agg/function/agg_vector_validity_helper.c b/tsl/src/nodes/vector_agg/function/agg_vector_validity_helper.c index ac3a95055a0..9dc1cfe853c 100644 --- a/tsl/src/nodes/vector_agg/function/agg_vector_validity_helper.c +++ b/tsl/src/nodes/vector_agg/function/agg_vector_validity_helper.c @@ -11,62 +11,40 @@ */ static pg_attribute_always_inline void -FUNCTION_NAME(vector_impl_arrow)(void *agg_state, const ArrowArray *vector, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) +FUNCTION_NAME(vector_impl_arrow)(void *agg_state, const ArrowArray *vector, const uint64 *filter, + MemoryContext agg_extra_mctx) { const int n = vector->length; const CTYPE *values = vector->buffers[1]; - FUNCTION_NAME(vector_impl)(agg_state, n, values, valid1, valid2, agg_extra_mctx); + FUNCTION_NAME(vector_impl)(agg_state, n, values, filter, agg_extra_mctx); } static pg_noinline void FUNCTION_NAME(vector_all_valid)(void *agg_state, const ArrowArray *vector, MemoryContext agg_extra_mctx) { - FUNCTION_NAME(vector_impl_arrow)(agg_state, vector, NULL, NULL, agg_extra_mctx); + FUNCTION_NAME(vector_impl_arrow)(agg_state, vector, NULL, agg_extra_mctx); } static pg_noinline void -FUNCTION_NAME(vector_one_validity)(void *agg_state, const ArrowArray *vector, const uint64 *valid, +FUNCTION_NAME(vector_one_validity)(void *agg_state, const ArrowArray *vector, const uint64 *filter, MemoryContext agg_extra_mctx) { - FUNCTION_NAME(vector_impl_arrow)(agg_state, vector, valid, NULL, agg_extra_mctx); -} - -static pg_noinline void -FUNCTION_NAME(vector_two_validity)(void *agg_state, const ArrowArray *vector, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) -{ - FUNCTION_NAME(vector_impl_arrow)(agg_state, vector, valid1, valid2, agg_extra_mctx); + FUNCTION_NAME(vector_impl_arrow)(agg_state, vector, filter, agg_extra_mctx); } static void FUNCTION_NAME(vector)(void *agg_state, const ArrowArray *vector, const uint64 *filter, MemoryContext agg_extra_mctx) { - const uint64 *row_validity = vector->buffers[0]; - - if (row_validity == NULL && filter == NULL) + if (filter == NULL) { /* All rows are valid and we don't have to check any validity bitmaps. */ FUNCTION_NAME(vector_all_valid)(agg_state, vector, agg_extra_mctx); } - else if (row_validity != NULL && filter == NULL) - { - /* Have to check only one bitmap -- row validity bitmap. */ - FUNCTION_NAME(vector_one_validity)(agg_state, vector, row_validity, agg_extra_mctx); - } - else if (filter != NULL && row_validity == NULL) - { - /* Have to check only one bitmap -- results of the vectorized filter. */ - FUNCTION_NAME(vector_one_validity)(agg_state, vector, filter, agg_extra_mctx); - } else { - /* - * Have to check both the row validity bitmap and the results of the - * vectorized filter. - */ - FUNCTION_NAME(vector_two_validity)(agg_state, vector, row_validity, filter, agg_extra_mctx); + /* Have to check only one combined validity bitmap. */ + FUNCTION_NAME(vector_one_validity)(agg_state, vector, filter, agg_extra_mctx); } } diff --git a/tsl/src/nodes/vector_agg/function/float48_accum_single.c b/tsl/src/nodes/vector_agg/function/float48_accum_single.c index 73743c5aa1a..deb2998d784 100644 --- a/tsl/src/nodes/vector_agg/function/float48_accum_single.c +++ b/tsl/src/nodes/vector_agg/function/float48_accum_single.c @@ -99,8 +99,7 @@ FUNCTION_NAME(emit)(void *agg_state, Datum *out_result, bool *out_isnull) * Youngs-Cramer update for rows after the first. */ static pg_attribute_always_inline void -FUNCTION_NAME(update)(const uint64 *valid1, const uint64 *valid2, const CTYPE *values, int row, - double *N, double *Sx +FUNCTION_NAME(update)(const uint64 *filter, const CTYPE *values, int row, double *N, double *Sx #ifdef NEED_SXX , double *Sxx @@ -108,7 +107,7 @@ FUNCTION_NAME(update)(const uint64 *valid1, const uint64 *valid2, const CTYPE *v ) { const CTYPE newval = values[row]; - if (!arrow_row_both_valid(valid1, valid2, row)) + if (!arrow_row_is_valid(filter, row)) { return; } @@ -185,20 +184,19 @@ FUNCTION_NAME(combine)(double *inout_N, double *inout_Sx, } #ifdef NEED_SXX -#define UPDATE(valid1, valid2, values, row, N, Sx, Sxx) \ - FUNCTION_NAME(update)(valid1, valid2, values, row, N, Sx, Sxx) +#define UPDATE(filter, values, row, N, Sx, Sxx) \ + FUNCTION_NAME(update)(filter, values, row, N, Sx, Sxx) #define COMBINE(inout_N, inout_Sx, inout_Sxx, N2, Sx2, Sxx2) \ FUNCTION_NAME(combine)(inout_N, inout_Sx, inout_Sxx, N2, Sx2, Sxx2) #else -#define UPDATE(valid1, valid2, values, row, N, Sx, Sxx) \ - FUNCTION_NAME(update)(valid1, valid2, values, row, N, Sx) +#define UPDATE(filter, values, row, N, Sx, Sxx) FUNCTION_NAME(update)(filter, values, row, N, Sx) #define COMBINE(inout_N, inout_Sx, inout_Sxx, N2, Sx2, Sxx2) \ FUNCTION_NAME(combine)(inout_N, inout_Sx, N2, Sx2) #endif static pg_attribute_always_inline void -FUNCTION_NAME(vector_impl)(void *agg_state, size_t n, const CTYPE *values, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) +FUNCTION_NAME(vector_impl)(void *agg_state, size_t n, const CTYPE *values, const uint64 *filter, + MemoryContext agg_extra_mctx) { /* * Vector registers can be up to 512 bits wide. @@ -228,7 +226,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, size_t n, const CTYPE *values, const for (; row < n; row++) { const CTYPE newval = values[row]; - if (arrow_row_both_valid(valid1, valid2, row)) + if (arrow_row_is_valid(filter, row)) { Narray[inner] = 1; Sxarray[inner] = newval; @@ -246,7 +244,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, size_t n, const CTYPE *values, const for (size_t inner = row % UNROLL_SIZE; inner > 0 && inner < UNROLL_SIZE && row < n; inner++, row++) { - UPDATE(valid1, valid2, values, row, &Narray[inner], &Sxarray[inner], &Sxxarray[inner]); + UPDATE(filter, values, row, &Narray[inner], &Sxarray[inner], &Sxxarray[inner]); } #endif @@ -258,13 +256,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, size_t n, const CTYPE *values, const { for (size_t inner = 0; inner < UNROLL_SIZE; inner++) { - UPDATE(valid1, - valid2, - values, - row + inner, - &Narray[inner], - &Sxarray[inner], - &Sxxarray[inner]); + UPDATE(filter, values, row + inner, &Narray[inner], &Sxarray[inner], &Sxxarray[inner]); } } @@ -274,7 +266,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, size_t n, const CTYPE *values, const for (; row < n; row++) { const size_t inner = row % UNROLL_SIZE; - UPDATE(valid1, valid2, values, row, &Narray[inner], &Sxarray[inner], &Sxxarray[inner]); + UPDATE(filter, values, row, &Narray[inner], &Sxarray[inner], &Sxxarray[inner]); } /* diff --git a/tsl/src/nodes/vector_agg/function/int128_accum_single.c b/tsl/src/nodes/vector_agg/function/int128_accum_single.c index bf60e64cd12..2e0b9ca25f2 100644 --- a/tsl/src/nodes/vector_agg/function/int128_accum_single.c +++ b/tsl/src/nodes/vector_agg/function/int128_accum_single.c @@ -72,8 +72,8 @@ FUNCTION_NAME(emit)(void *agg_state, Datum *out_result, bool *out_isnull) } static pg_attribute_always_inline void -FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) +FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *filter, + MemoryContext agg_extra_mctx) { int64 N = 0; int128 sumX = 0; @@ -82,7 +82,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui #endif for (int row = 0; row < n; row++) { - const bool row_ok = arrow_row_both_valid(valid1, valid2, row); + const bool row_ok = arrow_row_is_valid(filter, row); const CTYPE value = values[row]; N += row_ok; sumX += value * row_ok; diff --git a/tsl/src/nodes/vector_agg/function/int24_avg_accum_single.c b/tsl/src/nodes/vector_agg/function/int24_avg_accum_single.c index 62ebb5ad52b..fb90f116255 100644 --- a/tsl/src/nodes/vector_agg/function/int24_avg_accum_single.c +++ b/tsl/src/nodes/vector_agg/function/int24_avg_accum_single.c @@ -11,14 +11,14 @@ case PG_AGG_OID_HELPER(AGG_NAME, PG_TYPE): #else static pg_attribute_always_inline void -FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) +FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *filter, + MemoryContext agg_extra_mctx) { int64 batch_count = 0; int64 batch_sum = 0; for (int row = 0; row < n; row++) { - const bool row_ok = arrow_row_both_valid(valid1, valid2, row); + const bool row_ok = arrow_row_is_valid(filter, row); batch_count += row_ok; batch_sum += values[row] * row_ok; } diff --git a/tsl/src/nodes/vector_agg/function/int24_sum_single.c b/tsl/src/nodes/vector_agg/function/int24_sum_single.c index 8bfb15676ae..f7251599a90 100644 --- a/tsl/src/nodes/vector_agg/function/int24_sum_single.c +++ b/tsl/src/nodes/vector_agg/function/int24_sum_single.c @@ -11,8 +11,8 @@ case PG_AGG_OID_HELPER(AGG_NAME, PG_TYPE): #else static pg_attribute_always_inline void -FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) +FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *filter, + MemoryContext agg_extra_mctx) { Int24SumState *state = (Int24SumState *) agg_state; @@ -37,7 +37,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui bool have_result = false; for (int row = 0; row < n; row++) { - const bool row_ok = arrow_row_both_valid(valid1, valid2, row); + const bool row_ok = arrow_row_is_valid(filter, row); batch_sum += values[row] * row_ok; have_result |= row_ok; } diff --git a/tsl/src/nodes/vector_agg/function/minmax_arithmetic_single.c b/tsl/src/nodes/vector_agg/function/minmax_arithmetic_single.c index 6d110fcdc34..e4b94abdf21 100644 --- a/tsl/src/nodes/vector_agg/function/minmax_arithmetic_single.c +++ b/tsl/src/nodes/vector_agg/function/minmax_arithmetic_single.c @@ -10,8 +10,8 @@ case PG_AGG_OID_HELPER(AGG_NAME, PG_TYPE): return &FUNCTION_NAME(argdef); #else static pg_attribute_always_inline void -FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) +FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *filter, + MemoryContext agg_extra_mctx) { MinMaxState *state = (MinMaxState *) agg_state; @@ -20,7 +20,7 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui for (int row = 0; row < n; row++) { const CTYPE new_value = values[row]; - const bool new_value_ok = arrow_row_both_valid(valid1, valid2, row); + const bool new_value_ok = arrow_row_is_valid(filter, row); /* * Note that we have to properly handle NaNs and Infinities for floats. diff --git a/tsl/src/nodes/vector_agg/function/sum_float_single.c b/tsl/src/nodes/vector_agg/function/sum_float_single.c index 6b56b433c89..c8fbea2d43a 100644 --- a/tsl/src/nodes/vector_agg/function/sum_float_single.c +++ b/tsl/src/nodes/vector_agg/function/sum_float_single.c @@ -21,8 +21,8 @@ FUNCTION_NAME(emit)(void *agg_state, Datum *out_result, bool *out_isnull) } static pg_attribute_always_inline void -FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *valid1, - const uint64 *valid2, MemoryContext agg_extra_mctx) +FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const uint64 *filter, + MemoryContext agg_extra_mctx) { /* * Vector registers can be up to 512 bits wide. @@ -46,15 +46,15 @@ FUNCTION_NAME(vector_impl)(void *agg_state, int n, const CTYPE *values, const ui * infinities and NaNs. */ #define INNER_LOOP \ - const bool valid = arrow_row_both_valid(valid1, valid2, row); \ + const bool row_valid = arrow_row_is_valid(filter, row); \ union \ { \ CTYPE f; \ MASKTYPE m; \ } u = { .f = values[row] }; \ - u.m &= valid ? ~(MASKTYPE) 0 : (MASKTYPE) 0; \ + u.m &= row_valid ? ~(MASKTYPE) 0 : (MASKTYPE) 0; \ *dest += u.f; \ - *have_result |= valid; + *have_result |= row_valid; INNER_LOOP }