Skip to content

Commit

Permalink
Implement vectorized aggregation with grouping on segmentby column (#…
Browse files Browse the repository at this point in the history
…7147)

This PR implements vectorized aggregation with grouping by segmentby
columns. It works in a limited number of cases: grouping columns also
have to be in the select list, with the order matching the order of
columns in the table, otherwise we run into a projection which prevents
vectorized aggregation.

It also adds `count(*)` function, this is done in the same PR because we
need a second aggregate function to improve testing/code coverage.
  • Loading branch information
akuzm authored Aug 29, 2024
1 parent bedc86e commit 0e99f56
Show file tree
Hide file tree
Showing 31 changed files with 3,733 additions and 2,829 deletions.
1 change: 1 addition & 0 deletions .unreleased/group_by_segmentby
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implements: #7147 Vectorize partial aggregation for sum(int4) with grouping on segmentby columns.
32 changes: 23 additions & 9 deletions src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,16 @@ char *ts_current_timestamp_mock = NULL;
int ts_guc_debug_toast_tuple_target = 128;

#ifdef TS_DEBUG
static const struct config_enum_entry require_vector_qual_options[] = {
{ "allow", RVQ_Allow, false },
{ "forbid", RVQ_Forbid, false },
{ "only", RVQ_Only, false },
{ NULL, 0, false }
};
static const struct config_enum_entry debug_require_options[] = { { "allow", DRO_Allow, false },
{ "forbid", DRO_Forbid, false },
{ "require", DRO_Require, false },
{ NULL, 0, false } };

DebugRequireOption ts_guc_debug_require_vector_qual = DRO_Allow;

DebugRequireOption ts_guc_debug_require_vector_agg = DRO_Allow;
#endif

DebugRequireVectorQual ts_guc_debug_require_vector_qual = RVQ_Allow;
bool ts_guc_debug_compression_path_info = false;

static bool ts_guc_enable_hypertable_create = true;
Expand Down Expand Up @@ -868,6 +869,19 @@ _guc_init(void)
/* assign_hook= */ NULL,
/* show_hook= */ NULL);

DefineCustomEnumVariable(/* name= */ MAKE_EXTOPTION("debug_require_vector_agg"),
/* short_desc= */
"ensure that vectorized aggregation is used or not",
/* long_desc= */ "this is for debugging purposes",
/* valueAddr= */ (int *) &ts_guc_debug_require_vector_agg,
/* bootValue= */ DRO_Allow,
/* options = */ debug_require_options,
/* context= */ PGC_USERSET,
/* flags= */ 0,
/* check_hook= */ NULL,
/* assign_hook= */ NULL,
/* show_hook= */ NULL);

DefineCustomEnumVariable(/* name= */ MAKE_EXTOPTION("debug_require_vector_qual"),
/* short_desc= */
"ensure that non-vectorized or vectorized filters are used in "
Expand All @@ -878,8 +892,8 @@ _guc_init(void)
"and "
"using the test templates is a pain",
/* valueAddr= */ (int *) &ts_guc_debug_require_vector_qual,
/* bootValue= */ RVQ_Allow,
/* options = */ require_vector_qual_options,
/* bootValue= */ DRO_Allow,
/* options = */ debug_require_options,
/* context= */ PGC_USERSET,
/* flags= */ 0,
/* check_hook= */ NULL,
Expand Down
17 changes: 11 additions & 6 deletions src/guc.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ extern char *ts_current_timestamp_mock;

extern TSDLLEXPORT int ts_guc_debug_toast_tuple_target;

typedef enum DebugRequireVectorQual
#ifdef TS_DEBUG
typedef enum DebugRequireOption
{
RVQ_Allow = 0,
RVQ_Forbid,
RVQ_Only
} DebugRequireVectorQual;
DRO_Allow = 0,
DRO_Forbid,
DRO_Require
} DebugRequireOption;

extern TSDLLEXPORT DebugRequireOption ts_guc_debug_require_vector_qual;

extern TSDLLEXPORT DebugRequireVectorQual ts_guc_debug_require_vector_qual;
extern TSDLLEXPORT DebugRequireOption ts_guc_debug_require_vector_agg;

#endif

extern TSDLLEXPORT bool ts_guc_debug_compression_path_info;

Expand Down
2 changes: 1 addition & 1 deletion tsl/src/compression/arrow_c_data_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct ArrowSchema
static pg_attribute_always_inline bool
arrow_row_is_valid(const uint64 *bitmap, size_t row_number)
{
if (bitmap == NULL)
if (likely(bitmap == NULL))
{
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions tsl/src/nodes/decompress_chunk/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,11 +1281,11 @@ decompress_chunk_plan_create(PlannerInfo *root, RelOptInfo *rel, CustomPath *pat
}

#ifdef TS_DEBUG
if (ts_guc_debug_require_vector_qual == RVQ_Forbid && list_length(vectorized_quals) > 0)
if (ts_guc_debug_require_vector_qual == DRO_Forbid && list_length(vectorized_quals) > 0)
{
elog(ERROR, "debug: encountered vector quals when they are disabled");
}
else if (ts_guc_debug_require_vector_qual == RVQ_Only)
else if (ts_guc_debug_require_vector_qual == DRO_Require)
{
if (list_length(decompress_plan->scan.plan.qual) > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions tsl/src/nodes/decompress_chunk/pred_vector_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ vector_array_predicate(VectorPredicate *vector_const_predicate, bool is_or,

for (size_t word = 0; word < result_words; word++)
{
array_result[word] = 0;
final_result[word] = 0;
}
return;
}
Expand All @@ -95,7 +95,7 @@ vector_array_predicate(VectorPredicate *vector_const_predicate, bool is_or,
single_result = single_result_storage;
for (size_t outer = 0; outer < result_words; outer++)
{
single_result[outer] = -1;
single_result[outer] = ~0ULL;
}
}
else
Expand Down
1 change: 1 addition & 0 deletions tsl/src/nodes/vector_agg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/exec.c ${CMAKE_CURRENT_SOURCE_DIR}/functions.c
${CMAKE_CURRENT_SOURCE_DIR}/grouping_policy_batch.c
${CMAKE_CURRENT_SOURCE_DIR}/plan.c)
target_sources(${TSL_LIBRARY_NAME} PRIVATE ${SOURCES})
Loading

0 comments on commit 0e99f56

Please sign in to comment.