@@ -1734,37 +1734,30 @@ unify_hypothetical_args(ParseState *pstate,
17341734 Oid * actual_arg_types ,
17351735 Oid * declared_arg_types )
17361736{
1737- Node * args [FUNC_MAX_ARGS ];
17381737 int numDirectArgs ,
17391738 numNonHypotheticalArgs ;
1740- int i ;
1741- ListCell * lc ;
1739+ int hargpos ;
17421740
17431741 numDirectArgs = list_length (fargs ) - numAggregatedArgs ;
17441742 numNonHypotheticalArgs = numDirectArgs - numAggregatedArgs ;
17451743 /* safety check (should only trigger with a misdeclared agg) */
17461744 if (numNonHypotheticalArgs < 0 )
17471745 elog (ERROR , "incorrect number of arguments to hypothetical-set aggregate" );
17481746
1749- /* Deconstruct fargs into an array for ease of subscripting */
1750- i = 0 ;
1751- foreach (lc , fargs )
1752- {
1753- args [i ++ ] = (Node * ) lfirst (lc );
1754- }
1755-
17561747 /* Check each hypothetical arg and corresponding aggregated arg */
1757- for (i = numNonHypotheticalArgs ; i < numDirectArgs ; i ++ )
1748+ for (hargpos = numNonHypotheticalArgs ; hargpos < numDirectArgs ; hargpos ++ )
17581749 {
1759- int aargpos = numDirectArgs + (i - numNonHypotheticalArgs );
1750+ int aargpos = numDirectArgs + (hargpos - numNonHypotheticalArgs );
1751+ ListCell * harg = list_nth_cell (fargs , hargpos );
1752+ ListCell * aarg = list_nth_cell (fargs , aargpos );
17601753 Oid commontype ;
17611754
17621755 /* A mismatch means AggregateCreate didn't check properly ... */
1763- if (declared_arg_types [i ] != declared_arg_types [aargpos ])
1756+ if (declared_arg_types [hargpos ] != declared_arg_types [aargpos ])
17641757 elog (ERROR , "hypothetical-set aggregate has inconsistent declared argument types" );
17651758
17661759 /* No need to unify if make_fn_arguments will coerce */
1767- if (declared_arg_types [i ] != ANYOID )
1760+ if (declared_arg_types [hargpos ] != ANYOID )
17681761 continue ;
17691762
17701763 /*
@@ -1773,38 +1766,31 @@ unify_hypothetical_args(ParseState *pstate,
17731766 * the aggregated values).
17741767 */
17751768 commontype = select_common_type (pstate ,
1776- list_make2 (args [ aargpos ], args [ i ] ),
1769+ list_make2 (lfirst ( aarg ), lfirst ( harg ) ),
17771770 "WITHIN GROUP" ,
17781771 NULL );
17791772
17801773 /*
17811774 * Perform the coercions. We don't need to worry about NamedArgExprs
17821775 * here because they aren't supported with aggregates.
17831776 */
1784- args [ i ] = coerce_type (pstate ,
1785- args [ i ] ,
1786- actual_arg_types [i ],
1787- commontype , -1 ,
1788- COERCION_IMPLICIT ,
1789- COERCE_IMPLICIT_CAST ,
1790- -1 );
1791- actual_arg_types [i ] = commontype ;
1792- args [ aargpos ] = coerce_type (pstate ,
1793- args [ aargpos ] ,
1794- actual_arg_types [aargpos ],
1795- commontype , -1 ,
1796- COERCION_IMPLICIT ,
1797- COERCE_IMPLICIT_CAST ,
1798- -1 );
1777+ lfirst ( harg ) = coerce_type (pstate ,
1778+ ( Node * ) lfirst ( harg ) ,
1779+ actual_arg_types [hargpos ],
1780+ commontype , -1 ,
1781+ COERCION_IMPLICIT ,
1782+ COERCE_IMPLICIT_CAST ,
1783+ -1 );
1784+ actual_arg_types [hargpos ] = commontype ;
1785+ lfirst ( aarg ) = coerce_type (pstate ,
1786+ ( Node * ) lfirst ( aarg ) ,
1787+ actual_arg_types [aargpos ],
1788+ commontype , -1 ,
1789+ COERCION_IMPLICIT ,
1790+ COERCE_IMPLICIT_CAST ,
1791+ -1 );
17991792 actual_arg_types [aargpos ] = commontype ;
18001793 }
1801-
1802- /* Reconstruct fargs from array */
1803- i = 0 ;
1804- foreach (lc , fargs )
1805- {
1806- lfirst (lc ) = args [i ++ ];
1807- }
18081794}
18091795
18101796
0 commit comments