Skip to content

Commit 04b8b08

Browse files
committed
Add countany aggregate function
1 parent 5781420 commit 04b8b08

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

vops.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,8 @@ Datum vops_count_accumulate(PG_FUNCTION_ARGS)
10201020
PG_FUNCTION_INFO_V1(vops_count_accumulate_any);
10211021
Datum vops_count_accumulate_any(PG_FUNCTION_ARGS)
10221022
{
1023-
vops_tile_hdr* opd = PG_GETARG_VOPS_HDR(0);
1024-
int64 count = PG_GETARG_INT64(1);
1023+
int64 count = PG_GETARG_INT64(0);
1024+
vops_tile_hdr* opd = PG_GETARG_VOPS_HDR(1);
10251025
uint64 mask = filter_mask & ~opd->empty_mask;
10261026
int i;
10271027
for (i = 0; i < TILE_SIZE; i++) {
@@ -2632,6 +2632,17 @@ typedef struct
26322632
} vops_mutator_context;
26332633

26342634

2635+
static Oid nodeType(Node* node)
2636+
{
2637+
switch (nodeTag(node))
2638+
{
2639+
case T_TargetEntry:
2640+
return exprType((Node*)((TargetEntry *)node)->expr);
2641+
default:
2642+
return exprType(node);
2643+
}
2644+
}
2645+
26352646
static void replace_count(vops_mutator_context* ctx)
26362647
{
26372648
Aggref* count = ctx->countall;
@@ -2641,7 +2652,7 @@ static void replace_count(vops_mutator_context* ctx)
26412652
{
26422653
count->aggfnoid = countany_oid;
26432654
count->aggstar = false;
2644-
count->aggargtypes = list_make1_oid(exprType(ctx->vector_col));
2655+
count->aggargtypes = list_make1_oid(nodeType(ctx->vector_col));
26452656
count->args = list_make1(ctx->vector_col);
26462657
}
26472658
else
@@ -2738,7 +2749,7 @@ vops_expression_tree_mutator(Node *node, void *context)
27382749
else if (IsA(node, NullTest))
27392750
{
27402751
NullTest* test = (NullTest*)node;
2741-
if (!test->argisrow && is_vops_type(exprType((Node*)test->arg)))
2752+
if (!test->argisrow && is_vops_type(nodeType((Node*)test->arg)))
27422753
{
27432754
ctx->has_vector_ops = true;
27442755
ctx->vector_col = (Node*)test->arg;
@@ -2764,11 +2775,10 @@ vops_expression_tree_mutator(Node *node, void *context)
27642775
Aggref* agg = (Aggref*)node;
27652776
if (agg->aggfnoid == count_oid) {
27662777
Assert(agg->aggstar);
2778+
ctx->countall = agg;
27672779
if (ctx->has_vector_ops) {
2768-
agg->aggfnoid = countall_oid;
2780+
replace_count(ctx);
27692781
ctx->countall = NULL;
2770-
} else {
2771-
ctx->countall = agg;
27722782
}
27732783
} else if (!agg->aggstar && !ctx->has_vector_ops) {
27742784
Assert(list_length(agg->aggargtypes) >= 1);

0 commit comments

Comments
 (0)