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

Commit3b8ba16

Browse files
committed
Tweak a few of the most heavily used function call points to zero out
just the significant fields of FunctionCallInfoData, rather than MemSet'ingthe whole struct to zero. Unused positions in the arg[] array willthereby contain garbage rather than zeroes. This buys back some of theperformance hit from increasing FUNC_MAX_ARGS. Also tweak tuplesort.ccode for more speed by marking some routines 'inline'. All togetherthese changes speed up simple sorts, like count(distinct int4column),by about 25% on a P4 running RH Linux 7.2.
1 parent53c5eda commit3b8ba16

File tree

3 files changed

+261
-188
lines changed

3 files changed

+261
-188
lines changed

‎src/backend/executor/nodeAgg.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* Portions Copyright (c) 1994, Regents of the University of California
4747
*
4848
* IDENTIFICATION
49-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.88 2002/09/28 20:00:19 tgl Exp $
49+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.89 2002/10/04 17:19:55 tgl Exp $
5050
*
5151
*-------------------------------------------------------------------------
5252
*/
@@ -275,8 +275,18 @@ advance_transition_function(AggStatePerAgg peraggstate,
275275
}
276276
}
277277

278-
/* OK to call the transition function */
279-
MemSet(&fcinfo,0,sizeof(fcinfo));
278+
/*
279+
* OK to call the transition function
280+
*
281+
* This is heavily-used code, so manually zero just the necessary fields
282+
* instead of using MemSet(). Compare FunctionCall2().
283+
*/
284+
285+
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
286+
fcinfo.context=NULL;
287+
fcinfo.resultinfo=NULL;
288+
fcinfo.isnull= false;
289+
280290
fcinfo.flinfo=&peraggstate->transfn;
281291
fcinfo.nargs=2;
282292
fcinfo.arg[0]=peraggstate->transValue;

‎src/backend/utils/fmgr/fmgr.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.62 2002/09/0420:31:30 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.63 2002/10/0417:19:55 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -689,6 +689,14 @@ fmgr_security_definer(PG_FUNCTION_ARGS)
689689

690690
/*-------------------------------------------------------------------------
691691
*Support routines for callers of fmgr-compatible functions
692+
*
693+
* NOTE: the simplest way to reliably initialize a FunctionCallInfoData
694+
* is to MemSet it to zeroes and then fill in the fields that should be
695+
* nonzero. However, in a few of the most heavily used paths, we instead
696+
* just zero the fields that must be zero. This saves a fair number of
697+
* cycles so it's worth the extra maintenance effort. Also see inlined
698+
* version of FunctionCall2 in utils/sort/tuplesort.c if you need to change
699+
* these routines!
692700
*-------------------------------------------------------------------------
693701
*/
694702

@@ -703,9 +711,15 @@ DirectFunctionCall1(PGFunction func, Datum arg1)
703711
FunctionCallInfoDatafcinfo;
704712
Datumresult;
705713

706-
MemSet(&fcinfo,0,sizeof(fcinfo));
714+
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
715+
fcinfo.flinfo=NULL;
716+
fcinfo.context=NULL;
717+
fcinfo.resultinfo=NULL;
718+
fcinfo.isnull= false;
719+
707720
fcinfo.nargs=1;
708721
fcinfo.arg[0]=arg1;
722+
fcinfo.argnull[0]= false;
709723

710724
result= (*func) (&fcinfo);
711725

@@ -723,10 +737,17 @@ DirectFunctionCall2(PGFunction func, Datum arg1, Datum arg2)
723737
FunctionCallInfoDatafcinfo;
724738
Datumresult;
725739

726-
MemSet(&fcinfo,0,sizeof(fcinfo));
740+
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
741+
fcinfo.flinfo=NULL;
742+
fcinfo.context=NULL;
743+
fcinfo.resultinfo=NULL;
744+
fcinfo.isnull= false;
745+
727746
fcinfo.nargs=2;
728747
fcinfo.arg[0]=arg1;
729748
fcinfo.arg[1]=arg2;
749+
fcinfo.argnull[0]= false;
750+
fcinfo.argnull[1]= false;
730751

731752
result= (*func) (&fcinfo);
732753

@@ -936,10 +957,15 @@ FunctionCall1(FmgrInfo *flinfo, Datum arg1)
936957
FunctionCallInfoDatafcinfo;
937958
Datumresult;
938959

939-
MemSet(&fcinfo,0,sizeof(fcinfo));
960+
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
961+
fcinfo.context=NULL;
962+
fcinfo.resultinfo=NULL;
963+
fcinfo.isnull= false;
964+
940965
fcinfo.flinfo=flinfo;
941966
fcinfo.nargs=1;
942967
fcinfo.arg[0]=arg1;
968+
fcinfo.argnull[0]= false;
943969

944970
result=FunctionCallInvoke(&fcinfo);
945971

@@ -957,11 +983,17 @@ FunctionCall2(FmgrInfo *flinfo, Datum arg1, Datum arg2)
957983
FunctionCallInfoDatafcinfo;
958984
Datumresult;
959985

960-
MemSet(&fcinfo,0,sizeof(fcinfo));
986+
/* MemSet(&fcinfo, 0, sizeof(fcinfo)); */
987+
fcinfo.context=NULL;
988+
fcinfo.resultinfo=NULL;
989+
fcinfo.isnull= false;
990+
961991
fcinfo.flinfo=flinfo;
962992
fcinfo.nargs=2;
963993
fcinfo.arg[0]=arg1;
964994
fcinfo.arg[1]=arg2;
995+
fcinfo.argnull[0]= false;
996+
fcinfo.argnull[1]= false;
965997

966998
result=FunctionCallInvoke(&fcinfo);
967999

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp