Commit 3b8ba163 authored by Tom Lane's avatar Tom Lane

Tweak a few of the most heavily used function call points to zero out

just the significant fields of FunctionCallInfoData, rather than MemSet'ing
the whole struct to zero.  Unused positions in the arg[] array will
thereby contain garbage rather than zeroes.  This buys back some of the
performance hit from increasing FUNC_MAX_ARGS.  Also tweak tuplesort.c
code for more speed by marking some routines 'inline'.  All together
these changes speed up simple sorts, like count(distinct int4column),
by about 25% on a P4 running RH Linux 7.2.
parent 53c5edac
......@@ -46,7 +46,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.88 2002/09/28 20:00:19 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.89 2002/10/04 17:19:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -275,8 +275,18 @@ advance_transition_function(AggStatePerAgg peraggstate,
}
}
/* OK to call the transition function */
MemSet(&fcinfo, 0, sizeof(fcinfo));
/*
* OK to call the transition function
*
* This is heavily-used code, so manually zero just the necessary fields
* instead of using MemSet(). Compare FunctionCall2().
*/
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
fcinfo.context = NULL;
fcinfo.resultinfo = NULL;
fcinfo.isnull = false;
fcinfo.flinfo = &peraggstate->transfn;
fcinfo.nargs = 2;
fcinfo.arg[0] = peraggstate->transValue;
......
......@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.62 2002/09/04 20:31:30 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.63 2002/10/04 17:19:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -689,6 +689,14 @@ fmgr_security_definer(PG_FUNCTION_ARGS)
/*-------------------------------------------------------------------------
* Support routines for callers of fmgr-compatible functions
*
* NOTE: the simplest way to reliably initialize a FunctionCallInfoData
* is to MemSet it to zeroes and then fill in the fields that should be
* nonzero. However, in a few of the most heavily used paths, we instead
* just zero the fields that must be zero. This saves a fair number of
* cycles so it's worth the extra maintenance effort. Also see inlined
* version of FunctionCall2 in utils/sort/tuplesort.c if you need to change
* these routines!
*-------------------------------------------------------------------------
*/
......@@ -703,9 +711,15 @@ DirectFunctionCall1(PGFunction func, Datum arg1)
FunctionCallInfoData fcinfo;
Datum result;
MemSet(&fcinfo, 0, sizeof(fcinfo));
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
fcinfo.flinfo = NULL;
fcinfo.context = NULL;
fcinfo.resultinfo = NULL;
fcinfo.isnull = false;
fcinfo.nargs = 1;
fcinfo.arg[0] = arg1;
fcinfo.argnull[0] = false;
result = (*func) (&fcinfo);
......@@ -723,10 +737,17 @@ DirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2)
FunctionCallInfoData fcinfo;
Datum result;
MemSet(&fcinfo, 0, sizeof(fcinfo));
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
fcinfo.flinfo = NULL;
fcinfo.context = NULL;
fcinfo.resultinfo = NULL;
fcinfo.isnull = false;
fcinfo.nargs = 2;
fcinfo.arg[0] = arg1;
fcinfo.arg[1] = arg2;
fcinfo.argnull[0] = false;
fcinfo.argnull[1] = false;
result = (*func) (&fcinfo);
......@@ -936,10 +957,15 @@ FunctionCall1(FmgrInfo *flinfo, Datum arg1)
FunctionCallInfoData fcinfo;
Datum result;
MemSet(&fcinfo, 0, sizeof(fcinfo));
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
fcinfo.context = NULL;
fcinfo.resultinfo = NULL;
fcinfo.isnull = false;
fcinfo.flinfo = flinfo;
fcinfo.nargs = 1;
fcinfo.arg[0] = arg1;
fcinfo.argnull[0] = false;
result = FunctionCallInvoke(&fcinfo);
......@@ -957,11 +983,17 @@ FunctionCall2(FmgrInfo *flinfo, Datum arg1, Datum arg2)
FunctionCallInfoData fcinfo;
Datum result;
MemSet(&fcinfo, 0, sizeof(fcinfo));
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
fcinfo.context = NULL;
fcinfo.resultinfo = NULL;
fcinfo.isnull = false;
fcinfo.flinfo = flinfo;
fcinfo.nargs = 2;
fcinfo.arg[0] = arg1;
fcinfo.arg[1] = arg2;
fcinfo.argnull[0] = false;
fcinfo.argnull[1] = false;
result = FunctionCallInvoke(&fcinfo);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment