Skip to content

Commit f21636e

Browse files
committed
Remove useless entries for aggregate functions from fmgrtab.c.
Gen_fmgrtab.pl treated aggregate functions the same as other built-in functions, which is wasteful because there is no real need to have entries for them in the fmgr_builtins[] table. Suppressing those entries saves about 3KB in the compiled table on my machine; which is not a lot but it's not nothing either, considering that that table is pretty "hot". The only outside code change needed is that ExecInitWindowAgg() can't be allowed to call fmgr_info_cxt() on a plain aggregate function. But that saves a few cycles anyway. Having done that, the aggregate_dummy() function is unreferenced and might as well be dropped. Using "aggregate_dummy" as the prosrc value for an aggregate is now just a documentation convention not something that matters. There was some discussion of using NULL instead to save a few bytes in pg_proc, but we'd have to remove prosrc's BKI_FORCE_NOT_NULL marking which doesn't seem a great idea. Anyway, it's possible there's client-side code that expects to see "aggregate_dummy" there, so I'm loath to change it without a strong reason. Discussion: https://postgr.es/m/533989.1604263665@sss.pgh.pa.us
1 parent 113d359 commit f21636e

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

src/backend/catalog/pg_aggregate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ AggregateCreate(const char *aggName,
620620
GetUserId(), /* proowner */
621621
INTERNALlanguageId, /* languageObjectId */
622622
InvalidOid, /* no validator */
623-
"aggregate_dummy", /* placeholder proc */
623+
"aggregate_dummy", /* placeholder (no such proc) */
624624
NULL, /* probin */
625625
PROKIND_AGGREGATE,
626626
false, /* security invoker (currently not

src/backend/executor/nodeAgg.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4935,24 +4935,6 @@ AggRegisterCallback(FunctionCallInfo fcinfo,
49354935
}
49364936

49374937

4938-
/*
4939-
* aggregate_dummy - dummy execution routine for aggregate functions
4940-
*
4941-
* This function is listed as the implementation (prosrc field) of pg_proc
4942-
* entries for aggregate functions. Its only purpose is to throw an error
4943-
* if someone mistakenly executes such a function in the normal way.
4944-
*
4945-
* Perhaps someday we could assign real meaning to the prosrc field of
4946-
* an aggregate?
4947-
*/
4948-
Datum
4949-
aggregate_dummy(PG_FUNCTION_ARGS)
4950-
{
4951-
elog(ERROR, "aggregate function %u called as normal function",
4952-
fcinfo->flinfo->fn_oid);
4953-
return (Datum) 0; /* keep compiler quiet */
4954-
}
4955-
49564938
/* ----------------------------------------------------------------
49574939
* Parallel Query Support
49584940
* ----------------------------------------------------------------

src/backend/executor/nodeWindowAgg.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,11 +2446,6 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags)
24462446
perfuncstate->wfuncstate = wfuncstate;
24472447
perfuncstate->wfunc = wfunc;
24482448
perfuncstate->numArguments = list_length(wfuncstate->args);
2449-
2450-
fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2451-
econtext->ecxt_per_query_memory);
2452-
fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
2453-
24542449
perfuncstate->winCollation = wfunc->inputcollid;
24552450

24562451
get_typlenbyval(wfunc->wintype,
@@ -2479,6 +2474,11 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags)
24792474
winobj->argstates = wfuncstate->args;
24802475
winobj->localmem = NULL;
24812476
perfuncstate->winobj = winobj;
2477+
2478+
/* It's a real window function, so set up to call it. */
2479+
fmgr_info_cxt(wfunc->winfnoid, &perfuncstate->flinfo,
2480+
econtext->ecxt_per_query_memory);
2481+
fmgr_info_set_expr((Node *) wfunc, &perfuncstate->flinfo);
24822482
}
24832483
}
24842484

src/backend/utils/Gen_fmgrtab.pl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
oid => $bki_values{oid},
7676
name => $bki_values{proname},
7777
lang => $bki_values{prolang},
78+
kind => $bki_values{prokind},
7879
strict => $bki_values{proisstrict},
7980
retset => $bki_values{proretset},
8081
nargs => $bki_values{pronargs},
@@ -195,8 +196,10 @@
195196
$sqlname .= "_" . $s->{args} if ($proname_counts{ $s->{name} } > 1);
196197
$sqlname =~ s/\s+/_/g;
197198
print $ofh "#define F_" . uc $sqlname . " $s->{oid}\n";
198-
# We want only one extern per internal-language function
199-
if ($s->{lang} eq 'internal' && !$seenit{ $s->{prosrc} })
199+
# We want only one extern per internal-language, non-aggregate function
200+
if ( $s->{lang} eq 'internal'
201+
&& $s->{kind} ne 'a'
202+
&& !$seenit{ $s->{prosrc} })
200203
{
201204
$seenit{ $s->{prosrc} } = 1;
202205
print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n";
@@ -214,6 +217,8 @@
214217
foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr)
215218
{
216219
next if $s->{lang} ne 'internal';
220+
# We do not need entries for aggregate functions
221+
next if $s->{kind} eq 'a';
217222

218223
print $tfh ",\n" if ($fmgr_count > 0);
219224
print $tfh

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy