|
13 | 13 | *
|
14 | 14 | *Copyright (c) 2001-2008, PostgreSQL Global Development Group
|
15 | 15 | *
|
16 |
| - *$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.184 2008/11/04 11:04:06 petere Exp $ |
| 16 | + *$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.185 2008/12/08 15:44:54 tgl Exp $ |
17 | 17 | * ----------
|
18 | 18 | */
|
19 | 19 | #include"postgres.h"
|
@@ -967,55 +967,60 @@ pgstat_vacuum_stat(void)
|
967 | 967 | hash_destroy(htab);
|
968 | 968 |
|
969 | 969 | /*
|
970 |
| - * Now repeat the above steps for functions. |
| 970 | + * Now repeat the above steps for functions. However, we needn't bother |
| 971 | + * in the common case where no function stats are being collected. |
971 | 972 | */
|
972 |
| -htab=pgstat_collect_oids(ProcedureRelationId); |
| 973 | +if (dbentry->functions!=NULL&& |
| 974 | +hash_get_num_entries(dbentry->functions)>0) |
| 975 | +{ |
| 976 | +htab=pgstat_collect_oids(ProcedureRelationId); |
973 | 977 |
|
974 |
| -pgstat_setheader(&f_msg.m_hdr,PGSTAT_MTYPE_FUNCPURGE); |
975 |
| -f_msg.m_databaseid=MyDatabaseId; |
976 |
| -f_msg.m_nentries=0; |
| 978 | +pgstat_setheader(&f_msg.m_hdr,PGSTAT_MTYPE_FUNCPURGE); |
| 979 | +f_msg.m_databaseid=MyDatabaseId; |
| 980 | +f_msg.m_nentries=0; |
977 | 981 |
|
978 |
| -hash_seq_init(&hstat,dbentry->functions); |
979 |
| -while ((funcentry= (PgStat_StatFuncEntry*)hash_seq_search(&hstat))!=NULL) |
980 |
| -{ |
981 |
| -Oidfuncid=funcentry->functionid; |
| 982 | +hash_seq_init(&hstat,dbentry->functions); |
| 983 | +while ((funcentry= (PgStat_StatFuncEntry*)hash_seq_search(&hstat))!=NULL) |
| 984 | +{ |
| 985 | +Oidfuncid=funcentry->functionid; |
982 | 986 |
|
983 |
| -CHECK_FOR_INTERRUPTS(); |
| 987 | +CHECK_FOR_INTERRUPTS(); |
984 | 988 |
|
985 |
| -if (hash_search(htab, (void*)&funcid,HASH_FIND,NULL)!=NULL) |
986 |
| -continue; |
| 989 | +if (hash_search(htab, (void*)&funcid,HASH_FIND,NULL)!=NULL) |
| 990 | +continue; |
987 | 991 |
|
988 |
| -/* |
989 |
| - * Not there, so add this function's Oid to the message |
990 |
| - */ |
991 |
| -f_msg.m_functionid[f_msg.m_nentries++]=funcid; |
| 992 | +/* |
| 993 | + * Not there, so add this function's Oid to the message |
| 994 | + */ |
| 995 | +f_msg.m_functionid[f_msg.m_nentries++]=funcid; |
| 996 | + |
| 997 | +/* |
| 998 | + * If the message is full, send it out and reinitialize to empty |
| 999 | + */ |
| 1000 | +if (f_msg.m_nentries >=PGSTAT_NUM_FUNCPURGE) |
| 1001 | +{ |
| 1002 | +len= offsetof(PgStat_MsgFuncpurge,m_functionid[0]) |
| 1003 | ++f_msg.m_nentries*sizeof(Oid); |
| 1004 | + |
| 1005 | +pgstat_send(&f_msg,len); |
| 1006 | + |
| 1007 | +f_msg.m_nentries=0; |
| 1008 | +} |
| 1009 | +} |
992 | 1010 |
|
993 | 1011 | /*
|
994 |
| - *If themessage is full, send it out and reinitialize to empty |
| 1012 | + *Send therest |
995 | 1013 | */
|
996 |
| -if (f_msg.m_nentries >=PGSTAT_NUM_FUNCPURGE) |
| 1014 | +if (f_msg.m_nentries>0) |
997 | 1015 | {
|
998 | 1016 | len= offsetof(PgStat_MsgFuncpurge,m_functionid[0])
|
999 | 1017 | +f_msg.m_nentries*sizeof(Oid);
|
1000 | 1018 |
|
1001 | 1019 | pgstat_send(&f_msg,len);
|
1002 |
| - |
1003 |
| -f_msg.m_nentries=0; |
1004 | 1020 | }
|
1005 |
| -} |
1006 | 1021 |
|
1007 |
| -/* |
1008 |
| - * Send the rest |
1009 |
| - */ |
1010 |
| -if (f_msg.m_nentries>0) |
1011 |
| -{ |
1012 |
| -len= offsetof(PgStat_MsgFuncpurge,m_functionid[0]) |
1013 |
| -+f_msg.m_nentries*sizeof(Oid); |
1014 |
| - |
1015 |
| -pgstat_send(&f_msg,len); |
| 1022 | +hash_destroy(htab); |
1016 | 1023 | }
|
1017 |
| - |
1018 |
| -hash_destroy(htab); |
1019 | 1024 | }
|
1020 | 1025 |
|
1021 | 1026 |
|
|