-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vectorized aggregation with grouping by one fixed-size column (#7341)
The implementation uses the Postgres simplehash hash table for by-value fixed-size compressed columns. The biggest improvement on a "sensible" query is about 90%, and a couple of queries show bigger improvements but these are very synthetic cases that don't make much sense: https://grafana.ops.savannah-dev.timescale.com/d/fasYic_4z/compare-akuzm?orgId=1&var-branch=All&var-run1=3815&var-run2=3816&var-threshold=0.02&var-use_historical_thresholds=true&var-threshold_expression=2%20%2A%20percentile_cont%280.90%29&var-exact_suite_version=false&from=now-2d&to=now --------- Signed-off-by: Alexander Kuzmenkov <[email protected]> Co-authored-by: Erik Nordström <[email protected]>
- Loading branch information
Showing
36 changed files
with
4,688 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Implements: #7341 Vectorized aggregation with grouping by one fixed-size by-value compressed column (such as arithmetic types). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
add_subdirectory(function) | ||
add_subdirectory(hashing) | ||
set(SOURCES | ||
${CMAKE_CURRENT_SOURCE_DIR}/exec.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/grouping_policy_batch.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/grouping_policy_hash.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/plan.c) | ||
target_sources(${TSL_LIBRARY_NAME} PRIVATE ${SOURCES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tsl/src/nodes/vector_agg/function/agg_many_vector_helper.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* This file and its contents are licensed under the Timescale License. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-TIMESCALE for a copy of the license. | ||
*/ | ||
|
||
/* | ||
* A generic implementation of adding the given batch to many aggregate function | ||
* states with given offsets. Used for hash aggregation, and builds on the | ||
* FUNCTION_NAME(one) function, which adds one passing non-null row to the given | ||
* aggregate function state. | ||
*/ | ||
static pg_attribute_always_inline void | ||
FUNCTION_NAME(many_vector_impl)(void *restrict agg_states, const uint32 *offsets, | ||
const uint64 *filter, int start_row, int end_row, | ||
const ArrowArray *vector, MemoryContext agg_extra_mctx) | ||
{ | ||
FUNCTION_NAME(state) *restrict states = (FUNCTION_NAME(state) *) agg_states; | ||
const CTYPE *values = vector->buffers[1]; | ||
MemoryContext old = MemoryContextSwitchTo(agg_extra_mctx); | ||
for (int row = start_row; row < end_row; row++) | ||
{ | ||
const CTYPE value = values[row]; | ||
FUNCTION_NAME(state) *restrict state = &states[offsets[row]]; | ||
if (arrow_row_is_valid(filter, row)) | ||
{ | ||
Assert(offsets[row] != 0); | ||
FUNCTION_NAME(one)(state, value); | ||
} | ||
} | ||
MemoryContextSwitchTo(old); | ||
} | ||
|
||
static pg_noinline void | ||
FUNCTION_NAME(many_vector_all_valid)(void *restrict agg_states, const uint32 *offsets, | ||
int start_row, int end_row, const ArrowArray *vector, | ||
MemoryContext agg_extra_mctx) | ||
{ | ||
FUNCTION_NAME(many_vector_impl) | ||
(agg_states, offsets, NULL, start_row, end_row, vector, agg_extra_mctx); | ||
} | ||
|
||
static void | ||
FUNCTION_NAME(many_vector)(void *restrict agg_states, const uint32 *offsets, const uint64 *filter, | ||
int start_row, int end_row, const ArrowArray *vector, | ||
MemoryContext agg_extra_mctx) | ||
{ | ||
if (filter == NULL) | ||
{ | ||
FUNCTION_NAME(many_vector_all_valid) | ||
(agg_states, offsets, start_row, end_row, vector, agg_extra_mctx); | ||
} | ||
else | ||
{ | ||
FUNCTION_NAME(many_vector_impl) | ||
(agg_states, offsets, filter, start_row, end_row, vector, agg_extra_mctx); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.