@@ -1017,6 +1017,21 @@ Datum vops_count_accumulate(PG_FUNCTION_ARGS)
1017
1017
PG_RETURN_INT64 (count );
1018
1018
}
1019
1019
1020
+ PG_FUNCTION_INFO_V1 (vops_count_accumulate_any );
1021
+ Datum vops_count_accumulate_any (PG_FUNCTION_ARGS )
1022
+ {
1023
+ vops_tile_hdr * opd = PG_GETARG_VOPS_HDR (0 );
1024
+ int64 count = PG_GETARG_INT64 (1 );
1025
+ uint64 mask = filter_mask & ~opd -> empty_mask ;
1026
+ int i ;
1027
+ for (i = 0 ; i < TILE_SIZE ; i ++ ) {
1028
+ if (mask & ((uint64 )1 << i )) {
1029
+ count += 1 ;
1030
+ }
1031
+ }
1032
+ PG_RETURN_INT64 (count );
1033
+ }
1034
+
1020
1035
static EState * estate ;
1021
1036
static TupleTableSlot * slot ;
1022
1037
static Relation rel ;
@@ -2603,6 +2618,7 @@ static Oid vops_and_oid;
2603
2618
static Oid vops_or_oid ;
2604
2619
static Oid vops_not_oid ;
2605
2620
static Oid countall_oid ;
2621
+ static Oid countany_oid ;
2606
2622
static Oid count_oid ;
2607
2623
static Oid is_null_oid ;
2608
2624
static Oid is_not_null_oid ;
@@ -2611,9 +2627,31 @@ static Oid coalesce_oids[VOPS_LAST];
2611
2627
typedef struct
2612
2628
{
2613
2629
Aggref * countall ;
2630
+ Node * vector_col ;
2614
2631
bool has_vector_ops ;
2615
2632
} vops_mutator_context ;
2616
2633
2634
+
2635
+ static void replace_count (vops_mutator_context * ctx )
2636
+ {
2637
+ Aggref * count = ctx -> countall ;
2638
+ if (count != NULL )
2639
+ {
2640
+ if (ctx -> vector_col )
2641
+ {
2642
+ count -> aggfnoid = countany_oid ;
2643
+ count -> aggstar = false;
2644
+ count -> aggargtypes = list_make1_oid (exprType (ctx -> vector_col ));
2645
+ count -> args = list_make1 (ctx -> vector_col );
2646
+ }
2647
+ else
2648
+ {
2649
+ count -> aggfnoid = countall_oid ;
2650
+ }
2651
+ ctx -> countall = NULL ;
2652
+ }
2653
+ }
2654
+
2617
2655
static Node *
2618
2656
vops_expression_tree_mutator (Node * node , void * context )
2619
2657
{
@@ -2626,6 +2664,7 @@ vops_expression_tree_mutator(Node *node, void *context)
2626
2664
{
2627
2665
vops_mutator_context save_ctx = * ctx ;
2628
2666
ctx -> countall = NULL ;
2667
+ ctx -> vector_col = NULL ;
2629
2668
ctx -> has_vector_ops = false;
2630
2669
node = (Node * ) query_tree_mutator ((Query * ) node ,
2631
2670
vops_expression_tree_mutator ,
@@ -2702,10 +2741,8 @@ vops_expression_tree_mutator(Node *node, void *context)
2702
2741
if (!test -> argisrow && is_vops_type (exprType ((Node * )test -> arg )))
2703
2742
{
2704
2743
ctx -> has_vector_ops = true;
2705
- if (ctx -> countall ) {
2706
- ctx -> countall -> aggfnoid = countall_oid ;
2707
- ctx -> countall = NULL ;
2708
- }
2744
+ ctx -> vector_col = (Node * )test -> arg ;
2745
+ replace_count (ctx );
2709
2746
return (Node * )makeFuncExpr (filter_oid , BOOLOID ,
2710
2747
list_make1 (makeFuncExpr (test -> nulltesttype == IS_NULL
2711
2748
? is_null_oid
@@ -2720,10 +2757,7 @@ vops_expression_tree_mutator(Node *node, void *context)
2720
2757
else if (IsA (node , FuncExpr ) && !ctx -> has_vector_ops && ((FuncExpr * )node )-> funcid == filter_oid )
2721
2758
{
2722
2759
ctx -> has_vector_ops = true;
2723
- if (ctx -> countall ) {
2724
- ctx -> countall -> aggfnoid = countall_oid ;
2725
- ctx -> countall = NULL ;
2726
- }
2760
+ replace_count (ctx );
2727
2761
}
2728
2762
else if (IsA (node , Aggref ))
2729
2763
{
@@ -2741,10 +2775,8 @@ vops_expression_tree_mutator(Node *node, void *context)
2741
2775
if (is_vops_type (linitial_oid (agg -> aggargtypes )))
2742
2776
{
2743
2777
ctx -> has_vector_ops = true;
2744
- if (ctx -> countall ) {
2745
- ctx -> countall -> aggfnoid = countall_oid ;
2746
- ctx -> countall = NULL ;
2747
- }
2778
+ ctx -> vector_col = (Node * )linitial (agg -> args );
2779
+ replace_count (ctx );
2748
2780
}
2749
2781
}
2750
2782
}
@@ -2786,6 +2818,7 @@ static void vops_post_parse_analysis_hook(ParseState *pstate, Query *query)
2786
2818
vops_not_oid = LookupFuncName (list_make1 (makeString ("vops_bool_not" )), 1 , profile , false);
2787
2819
count_oid = LookupFuncName (list_make1 (makeString ("count" )), 0 , profile , false);
2788
2820
countall_oid = LookupFuncName (list_make1 (makeString ("countall" )), 0 , profile , false);
2821
+ countany_oid = LookupFuncName (list_make1 (makeString ("countany" )), 1 , & any , false);
2789
2822
is_null_oid = LookupFuncName (list_make1 (makeString ("is_null" )), 1 , & any , false);
2790
2823
2791
2824
for (i = VOPS_CHAR ; i < VOPS_LAST ; i ++ ) {
0 commit comments