Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit847e46a

Browse files
committed
Avoid extra AggCheckCallContext() checks in ordered-set aggregates.
In the transition functions, we don't really need to recheck this after thefirst call. I had been feeling paranoid about possibly getting a non-nullargument value in some other context; but it's probably game over anywayif we have a non-null "internal" value that's not what we are expecting.In the final functions, the general convention in pre-existing finalfunctions seems to be that an Assert() is good enough, so do it like thathere too.This seems to save a few tenths of a percent of overall query runtime,which isn't much, but still it's just overhead if there's not a plausiblecase where the checks would fire.
1 parente6336b8 commit847e46a

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

‎src/backend/utils/adt/orderedsetaggs.c

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ ordered_set_startup(FunctionCallInfo fcinfo, bool use_tuples)
122122
intnumSortCols;
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'sgroup-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
boolisnull;
436426
int64rownum;
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
doubleproportion;
543531
boolisnull;
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
boolisnull= true;
753739
inti;
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
boolisnull;
876860
inti;
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
boolshouldfree;
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
inti;
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
MemoryContexttmpcontext;
13061284
inti;
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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp