@@ -1734,37 +1734,30 @@ unify_hypothetical_args(ParseState *pstate,
1734
1734
Oid * actual_arg_types ,
1735
1735
Oid * declared_arg_types )
1736
1736
{
1737
- Node * args [FUNC_MAX_ARGS ];
1738
1737
int numDirectArgs ,
1739
1738
numNonHypotheticalArgs ;
1740
- int i ;
1741
- ListCell * lc ;
1739
+ int hargpos ;
1742
1740
1743
1741
numDirectArgs = list_length (fargs ) - numAggregatedArgs ;
1744
1742
numNonHypotheticalArgs = numDirectArgs - numAggregatedArgs ;
1745
1743
/* safety check (should only trigger with a misdeclared agg) */
1746
1744
if (numNonHypotheticalArgs < 0 )
1747
1745
elog (ERROR , "incorrect number of arguments to hypothetical-set aggregate" );
1748
1746
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
-
1756
1747
/* Check each hypothetical arg and corresponding aggregated arg */
1757
- for (i = numNonHypotheticalArgs ; i < numDirectArgs ; i ++ )
1748
+ for (hargpos = numNonHypotheticalArgs ; hargpos < numDirectArgs ; hargpos ++ )
1758
1749
{
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 );
1760
1753
Oid commontype ;
1761
1754
1762
1755
/* 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 ])
1764
1757
elog (ERROR , "hypothetical-set aggregate has inconsistent declared argument types" );
1765
1758
1766
1759
/* No need to unify if make_fn_arguments will coerce */
1767
- if (declared_arg_types [i ] != ANYOID )
1760
+ if (declared_arg_types [hargpos ] != ANYOID )
1768
1761
continue ;
1769
1762
1770
1763
/*
@@ -1773,38 +1766,31 @@ unify_hypothetical_args(ParseState *pstate,
1773
1766
* the aggregated values).
1774
1767
*/
1775
1768
commontype = select_common_type (pstate ,
1776
- list_make2 (args [ aargpos ], args [ i ] ),
1769
+ list_make2 (lfirst ( aarg ), lfirst ( harg ) ),
1777
1770
"WITHIN GROUP" ,
1778
1771
NULL );
1779
1772
1780
1773
/*
1781
1774
* Perform the coercions. We don't need to worry about NamedArgExprs
1782
1775
* here because they aren't supported with aggregates.
1783
1776
*/
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 );
1799
1792
actual_arg_types [aargpos ] = commontype ;
1800
1793
}
1801
-
1802
- /* Reconstruct fargs from array */
1803
- i = 0 ;
1804
- foreach (lc , fargs )
1805
- {
1806
- lfirst (lc ) = args [i ++ ];
1807
- }
1808
1794
}
1809
1795
1810
1796
0 commit comments