@@ -122,8 +122,8 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples)
122122 int numSortCols ;
123123
124124 /*
125- * Check we're called as aggregate, and get the Agg node's
126- * group-lifespan context
125+ * Check we're called as aggregate ( and not a window function), and
126+ * get the Agg node's group-lifespan context
127127 */
128128 if (AggCheckCallContext (fcinfo , & gcontext ) != AGG_CONTEXT_AGGREGATE )
129129 elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
@@ -356,12 +356,7 @@ ordered_set_transition(PG_FUNCTION_ARGS)
356356 if (PG_ARGISNULL (0 ))
357357 osastate = ordered_set_startup (fcinfo , false);
358358 else
359- {
360- /* safety check */
361- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
362- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
363359 osastate = (OSAPerGroupState * ) PG_GETARG_POINTER (0 );
364- }
365360
366361 /* Load the datum into the tuplesort object, but only if it's not null */
367362 if (!PG_ARGISNULL (1 ))
@@ -389,12 +384,7 @@ ordered_set_transition_multi(PG_FUNCTION_ARGS)
389384 if (PG_ARGISNULL (0 ))
390385 osastate = ordered_set_startup (fcinfo , true);
391386 else
392- {
393- /* safety check */
394- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
395- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
396387 osastate = (OSAPerGroupState * ) PG_GETARG_POINTER (0 );
397- }
398388
399389 /* Form a tuple from all the other inputs besides the transition value */
400390 slot = osastate -> qstate -> tupslot ;
@@ -435,9 +425,7 @@ percentile_disc_final(PG_FUNCTION_ARGS)
435425 bool isnull ;
436426 int64 rownum ;
437427
438- /* safety check */
439- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
440- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
428+ Assert (AggCheckCallContext (fcinfo , NULL ) == AGG_CONTEXT_AGGREGATE );
441429
442430 /* Get and check the percentile argument */
443431 if (PG_ARGISNULL (1 ))
@@ -542,9 +530,7 @@ percentile_cont_final_common(FunctionCallInfo fcinfo,
542530 double proportion ;
543531 bool isnull ;
544532
545- /* safety check */
546- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
547- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
533+ Assert (AggCheckCallContext (fcinfo , NULL ) == AGG_CONTEXT_AGGREGATE );
548534
549535 /* Get and check the percentile argument */
550536 if (PG_ARGISNULL (1 ))
@@ -752,9 +738,7 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS)
752738 bool isnull = true;
753739 int i ;
754740
755- /* safety check */
756- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
757- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
741+ Assert (AggCheckCallContext (fcinfo , NULL ) == AGG_CONTEXT_AGGREGATE );
758742
759743 /* If there were no regular rows, the result is NULL */
760744 if (PG_ARGISNULL (0 ))
@@ -875,9 +859,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo,
875859 bool isnull ;
876860 int i ;
877861
878- /* safety check */
879- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
880- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
862+ Assert (AggCheckCallContext (fcinfo , NULL ) == AGG_CONTEXT_AGGREGATE );
881863
882864 /* If there were no regular rows, the result is NULL */
883865 if (PG_ARGISNULL (0 ))
@@ -1045,9 +1027,7 @@ mode_final(PG_FUNCTION_ARGS)
10451027 FmgrInfo * equalfn ;
10461028 bool shouldfree ;
10471029
1048- /* safety check */
1049- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
1050- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
1030+ Assert (AggCheckCallContext (fcinfo , NULL ) == AGG_CONTEXT_AGGREGATE );
10511031
10521032 /* If there were no regular rows, the result is NULL */
10531033 if (PG_ARGISNULL (0 ))
@@ -1173,9 +1153,7 @@ hypothetical_rank_common(FunctionCallInfo fcinfo, int flag,
11731153 TupleTableSlot * slot ;
11741154 int i ;
11751155
1176- /* safety check */
1177- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
1178- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
1156+ Assert (AggCheckCallContext (fcinfo , NULL ) == AGG_CONTEXT_AGGREGATE );
11791157
11801158 /* If there were no regular rows, the rank is always 1 */
11811159 if (PG_ARGISNULL (0 ))
@@ -1305,9 +1283,7 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS)
13051283 MemoryContext tmpcontext ;
13061284 int i ;
13071285
1308- /* safety check */
1309- if (AggCheckCallContext (fcinfo , NULL ) != AGG_CONTEXT_AGGREGATE )
1310- elog (ERROR , "ordered-set aggregate called in non-aggregate context" );
1286+ Assert (AggCheckCallContext (fcinfo , NULL ) == AGG_CONTEXT_AGGREGATE );
13111287
13121288 /* If there were no regular rows, the rank is always 1 */
13131289 if (PG_ARGISNULL (0 ))
0 commit comments