@@ -1017,6 +1017,21 @@ Datum vops_count_accumulate(PG_FUNCTION_ARGS)
10171017PG_RETURN_INT64 (count );
10181018}
10191019
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+
10201035static EState * estate ;
10211036static TupleTableSlot * slot ;
10221037static Relation rel ;
@@ -2603,6 +2618,7 @@ static Oid vops_and_oid;
26032618static Oid vops_or_oid ;
26042619static Oid vops_not_oid ;
26052620static Oid countall_oid ;
2621+ static Oid countany_oid ;
26062622static Oid count_oid ;
26072623static Oid is_null_oid ;
26082624static Oid is_not_null_oid ;
@@ -2611,9 +2627,31 @@ static Oid coalesce_oids[VOPS_LAST];
26112627typedef struct
26122628{
26132629Aggref * countall ;
2630+ Node * vector_col ;
26142631bool has_vector_ops ;
26152632}vops_mutator_context ;
26162633
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+
26172655static Node *
26182656vops_expression_tree_mutator (Node * node ,void * context )
26192657{
@@ -2626,6 +2664,7 @@ vops_expression_tree_mutator(Node *node, void *context)
26262664{
26272665vops_mutator_context save_ctx = * ctx ;
26282666ctx -> countall = NULL ;
2667+ ctx -> vector_col = NULL ;
26292668ctx -> has_vector_ops = false;
26302669node = (Node * )query_tree_mutator ((Query * )node ,
26312670vops_expression_tree_mutator ,
@@ -2702,10 +2741,8 @@ vops_expression_tree_mutator(Node *node, void *context)
27022741if (!test -> argisrow && is_vops_type (exprType ((Node * )test -> arg )))
27032742{
27042743ctx -> 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 );
27092746return (Node * )makeFuncExpr (filter_oid ,BOOLOID ,
27102747list_make1 (makeFuncExpr (test -> nulltesttype == IS_NULL
27112748 ?is_null_oid
@@ -2720,10 +2757,7 @@ vops_expression_tree_mutator(Node *node, void *context)
27202757else if (IsA (node ,FuncExpr )&& !ctx -> has_vector_ops && ((FuncExpr * )node )-> funcid == filter_oid )
27212758{
27222759ctx -> has_vector_ops = true;
2723- if (ctx -> countall ) {
2724- ctx -> countall -> aggfnoid = countall_oid ;
2725- ctx -> countall = NULL ;
2726- }
2760+ replace_count (ctx );
27272761}
27282762else if (IsA (node ,Aggref ))
27292763{
@@ -2741,10 +2775,8 @@ vops_expression_tree_mutator(Node *node, void *context)
27412775if (is_vops_type (linitial_oid (agg -> aggargtypes )))
27422776{
27432777ctx -> 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 );
27482780}
27492781}
27502782}
@@ -2786,6 +2818,7 @@ static void vops_post_parse_analysis_hook(ParseState *pstate, Query *query)
27862818vops_not_oid = LookupFuncName (list_make1 (makeString ("vops_bool_not" )),1 ,profile , false);
27872819count_oid = LookupFuncName (list_make1 (makeString ("count" )),0 ,profile , false);
27882820countall_oid = LookupFuncName (list_make1 (makeString ("countall" )),0 ,profile , false);
2821+ countany_oid = LookupFuncName (list_make1 (makeString ("countany" )),1 ,& any , false);
27892822is_null_oid = LookupFuncName (list_make1 (makeString ("is_null" )),1 ,& any , false);
27902823
27912824for (i = VOPS_CHAR ;i < VOPS_LAST ;i ++ ) {