@@ -1020,8 +1020,8 @@ Datum vops_count_accumulate(PG_FUNCTION_ARGS)
10201020PG_FUNCTION_INFO_V1 (vops_count_accumulate_any );
10211021Datum 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 );
10251025uint64 mask = filter_mask & ~opd -> empty_mask ;
10261026int i ;
10271027for (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+
26352646static void replace_count (vops_mutator_context * ctx )
26362647{
26372648Aggref * count = ctx -> countall ;
@@ -2641,7 +2652,7 @@ static void replace_count(vops_mutator_context* ctx)
26412652{
26422653count -> aggfnoid = countany_oid ;
26432654count -> aggstar = false;
2644- count -> aggargtypes = list_make1_oid (exprType (ctx -> vector_col ));
2655+ count -> aggargtypes = list_make1_oid (nodeType (ctx -> vector_col ));
26452656count -> args = list_make1 (ctx -> vector_col );
26462657}
26472658else
@@ -2738,7 +2749,7 @@ vops_expression_tree_mutator(Node *node, void *context)
27382749else if (IsA (node ,NullTest ))
27392750{
27402751NullTest * 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{
27432754ctx -> has_vector_ops = true;
27442755ctx -> vector_col = (Node * )test -> arg ;
@@ -2764,11 +2775,10 @@ vops_expression_tree_mutator(Node *node, void *context)
27642775Aggref * agg = (Aggref * )node ;
27652776if (agg -> aggfnoid == count_oid ) {
27662777Assert (agg -> aggstar );
2778+ ctx -> countall = agg ;
27672779if (ctx -> has_vector_ops ) {
2768- agg -> aggfnoid = countall_oid ;
2780+ replace_count ( ctx ) ;
27692781ctx -> countall = NULL ;
2770- }else {
2771- ctx -> countall = agg ;
27722782}
27732783}else if (!agg -> aggstar && !ctx -> has_vector_ops ) {
27742784Assert (list_length (agg -> aggargtypes ) >=1 );