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

Commitb16a8f4

Browse files
committed
pg_stat_get_backend_idset should reset fmgr_info->fn_extra at end of
execution, so that it restarts correctly if query tree is used again.
1 parentf00da6d commitb16a8f4

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,33 +179,29 @@ Datum
179179
pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
180180
{
181181
FmgrInfo*fmgr_info=fcinfo->flinfo;
182-
MemoryContextoldcxt;
183182
int32result;
184183

185-
if (fcinfo->resultinfo==NULL)
186-
elog(ERROR,"called in context that does not accept a set result (1)");
187-
if (!IsA(fcinfo->resultinfo,ReturnSetInfo))
188-
elog(ERROR,"called in context that does not accept a set result (2)");
184+
if (fcinfo->resultinfo==NULL||
185+
!IsA(fcinfo->resultinfo,ReturnSetInfo))
186+
elog(ERROR,"pg_stat_get_backend_idset: called in context that does not accept a set result");
189187

190188
if (fmgr_info->fn_extra==NULL)
191189
{
192190
if (fmgr_info->fn_mcxt==NULL)
193191
elog(ERROR,"No function memory context in set-function");
194-
195-
oldcxt=MemoryContextSwitchTo(fmgr_info->fn_mcxt);
196-
fmgr_info->fn_extra=palloc(sizeof(int32)*2);
197-
((int32*)(fmgr_info->fn_extra))[0]=0;
198-
((int32*)(fmgr_info->fn_extra))[1]=
199-
(int32)pgstat_fetch_stat_numbackends();
200-
MemoryContextSwitchTo(oldcxt);
192+
fmgr_info->fn_extra=MemoryContextAlloc(fmgr_info->fn_mcxt,
193+
2*sizeof(int));
194+
((int*)(fmgr_info->fn_extra))[0]=0;
195+
((int*)(fmgr_info->fn_extra))[1]=pgstat_fetch_stat_numbackends();
201196
}
202197

203-
((int32*)(fmgr_info->fn_extra))[0]+=1;
204-
result= ((int32*)(fmgr_info->fn_extra))[0];
205-
198+
((int*)(fmgr_info->fn_extra))[0]+=1;
199+
result= ((int*)(fmgr_info->fn_extra))[0];
206200

207-
if (result> ((int32*)(fmgr_info->fn_extra))[1])
201+
if (result> ((int*)(fmgr_info->fn_extra))[1])
208202
{
203+
pfree(fmgr_info->fn_extra);
204+
fmgr_info->fn_extra=NULL;
209205
((ReturnSetInfo*)(fcinfo->resultinfo))->isDone=ExprEndResult;
210206
PG_RETURN_NULL();
211207
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp