-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vectorized aggregation as separate plan node (#6784)
This PR is a little too big, but it proved difficult to split into parts because they are all dependent. * Move the vectorized aggregation into a separate plan node, which simplifies working with targetlist in DecompressChunk node. * Add a post-planning hook that replaces the normal partial aggregation node with the vectorized aggregation node. The advantage of this compared to planning on Path stage is that we know which columns support bulk decompression and which filters are vectorized. * Use the compressed batch API in vectorized aggregation. This simplifies the code. * Support vectorized aggregation after vectorized filters. * Add a simple generic interface for vectorized aggregate functions. For now the only function is still `sum(int4)`. * The parallel plans are now used more often, maybe because the old code didn't add costs for aggregation and just used the costs from DecompressChunk, so the costs of parallel plans were less different. The current code does the cost-based planning for normal aggregates, and then after planning replaces them with vectorized, so now we basically follow the plan choice that Postgres makes for the usual aggregation.
- Loading branch information
Showing
41 changed files
with
2,709 additions
and
1,759 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
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,88 @@ | ||
/* | ||
* This file and its contents are licensed under the Apache License 2.0. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-APACHE for a copy of the license. | ||
*/ | ||
|
||
#include <postgres.h> | ||
|
||
#include <nodes/pg_list.h> | ||
#include <port/pg_bitutils.h> | ||
|
||
#include "import/list.h" | ||
|
||
/* | ||
* This file contains source code that was copied and/or modified from | ||
* the PostgreSQL database, which is licensed under the open-source | ||
* PostgreSQL License. Please see the NOTICE at the top level | ||
* directory for a copy of the PostgreSQL License. | ||
* | ||
* Copied from PostgreSQL 15.0 (2a7ce2e2ce474504a707ec03e128fde66cfb8b48) | ||
* without modifications. | ||
*/ | ||
|
||
/* Overhead for the fixed part of a List header, measured in ListCells */ | ||
#define LIST_HEADER_OVERHEAD ((int) ((offsetof(List, initial_elements) - 1) / sizeof(ListCell) + 1)) | ||
|
||
/* | ||
* Return a freshly allocated List with room for at least min_size cells. | ||
* | ||
* Since empty non-NIL lists are invalid, new_list() sets the initial length | ||
* to min_size, effectively marking that number of cells as valid; the caller | ||
* is responsible for filling in their data. | ||
*/ | ||
List * | ||
ts_new_list(NodeTag type, int min_size) | ||
{ | ||
List *newlist; | ||
int max_size; | ||
|
||
Assert(min_size > 0); | ||
|
||
/* | ||
* We allocate all the requested cells, and possibly some more, as part of | ||
* the same palloc request as the List header. This is a big win for the | ||
* typical case of short fixed-length lists. It can lose if we allocate a | ||
* moderately long list and then it gets extended; we'll be wasting more | ||
* initial_elements[] space than if we'd made the header small. However, | ||
* rounding up the request as we do in the normal code path provides some | ||
* defense against small extensions. | ||
*/ | ||
|
||
#ifndef DEBUG_LIST_MEMORY_USAGE | ||
|
||
/* | ||
* Normally, we set up a list with some extra cells, to allow it to grow | ||
* without a repalloc. Prefer cell counts chosen to make the total | ||
* allocation a power-of-2, since palloc would round it up to that anyway. | ||
* (That stops being true for very large allocations, but very long lists | ||
* are infrequent, so it doesn't seem worth special logic for such cases.) | ||
* | ||
* The minimum allocation is 8 ListCell units, providing either 4 or 5 | ||
* available ListCells depending on the machine's word width. Counting | ||
* palloc's overhead, this uses the same amount of space as a one-cell | ||
* list did in the old implementation, and less space for any longer list. | ||
* | ||
* We needn't worry about integer overflow; no caller passes min_size | ||
* that's more than twice the size of an existing list, so the size limits | ||
* within palloc will ensure that we don't overflow here. | ||
*/ | ||
max_size = pg_nextpower2_32(Max(8, min_size + LIST_HEADER_OVERHEAD)); | ||
max_size -= LIST_HEADER_OVERHEAD; | ||
#else | ||
|
||
/* | ||
* For debugging, don't allow any extra space. This forces any cell | ||
* addition to go through enlarge_list() and thus move the existing data. | ||
*/ | ||
max_size = min_size; | ||
#endif | ||
|
||
newlist = (List *) palloc(offsetof(List, initial_elements) + max_size * sizeof(ListCell)); | ||
newlist->type = type; | ||
newlist->length = min_size; | ||
newlist->max_length = max_size; | ||
newlist->elements = newlist->initial_elements; | ||
|
||
return newlist; | ||
} |
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,17 @@ | ||
/* | ||
* This file and its contents are licensed under the Apache License 2.0. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-APACHE for a copy of the license. | ||
*/ | ||
#pragma once | ||
|
||
#include "export.h" | ||
|
||
/* | ||
* This file contains source code that was copied and/or modified from | ||
* the PostgreSQL database, which is licensed under the open-source | ||
* PostgreSQL License. Please see the NOTICE at the top level | ||
* directory for a copy of the PostgreSQL License. | ||
*/ | ||
|
||
extern TSDLLEXPORT List *ts_new_list(NodeTag type, int min_size); |
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,13 @@ | ||
/* | ||
* This file and its contents are licensed under the Apache License 2.0. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-APACHE for a copy of the license. | ||
*/ | ||
#pragma once | ||
|
||
/* | ||
* This file defines the node name of Vector Aggregation custom node, to be | ||
* used in the Apache part of the Timescale extension. The node itself is in the | ||
* the TSL part. | ||
*/ | ||
#define VECTOR_AGG_NODE_NAME "VectorAgg" |
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.