@@ -122,8 +122,8 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples)
122122int numSortCols ;
123123
124124/*
125- * Check we're called as aggregate, andget the Agg node's
126- * group-lifespan context
125+ * Check we're called as aggregate ( andnot a window function), and
126+ *get the Agg node's group-lifespan context
127127 */
128128if (AggCheckCallContext (fcinfo ,& gcontext )!= AGG_CONTEXT_AGGREGATE )
129129elog (ERROR ,"ordered-set aggregate called in non-aggregate context" );
@@ -356,12 +356,7 @@ ordered_set_transition(PG_FUNCTION_ARGS)
356356if (PG_ARGISNULL (0 ))
357357osastate = ordered_set_startup (fcinfo , false);
358358else
359- {
360- /* safety check */
361- if (AggCheckCallContext (fcinfo ,NULL )!= AGG_CONTEXT_AGGREGATE )
362- elog (ERROR ,"ordered-set aggregate called in non-aggregate context" );
363359osastate = (OSAPerGroupState * )PG_GETARG_POINTER (0 );
364- }
365360
366361/* Load the datum into the tuplesort object, but only if it's not null */
367362if (!PG_ARGISNULL (1 ))
@@ -389,12 +384,7 @@ ordered_set_transition_multi(PG_FUNCTION_ARGS)
389384if (PG_ARGISNULL (0 ))
390385osastate = ordered_set_startup (fcinfo , true);
391386else
392- {
393- /* safety check */
394- if (AggCheckCallContext (fcinfo ,NULL )!= AGG_CONTEXT_AGGREGATE )
395- elog (ERROR ,"ordered-set aggregate called in non-aggregate context" );
396387osastate = (OSAPerGroupState * )PG_GETARG_POINTER (0 );
397- }
398388
399389/* Form a tuple from all the other inputs besides the transition value */
400390slot = osastate -> qstate -> tupslot ;
@@ -435,9 +425,7 @@ percentile_disc_final(PG_FUNCTION_ARGS)
435425bool isnull ;
436426int64 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 */
443431if (PG_ARGISNULL (1 ))
@@ -542,9 +530,7 @@ percentile_cont_final_common(FunctionCallInfo fcinfo,
542530double proportion ;
543531bool 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 */
550536if (PG_ARGISNULL (1 ))
@@ -752,9 +738,7 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS)
752738bool isnull = true;
753739int 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 */
760744if (PG_ARGISNULL (0 ))
@@ -875,9 +859,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo,
875859bool isnull ;
876860int 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 */
883865if (PG_ARGISNULL (0 ))
@@ -1045,9 +1027,7 @@ mode_final(PG_FUNCTION_ARGS)
10451027FmgrInfo * equalfn ;
10461028bool 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 */
10531033if (PG_ARGISNULL (0 ))
@@ -1173,9 +1153,7 @@ hypothetical_rank_common(FunctionCallInfo fcinfo, int flag,
11731153TupleTableSlot * slot ;
11741154int 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 */
11811159if (PG_ARGISNULL (0 ))
@@ -1305,9 +1283,7 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS)
13051283MemoryContext tmpcontext ;
13061284int 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 */
13131289if (PG_ARGISNULL (0 ))