PG-254: Postpone variable initialization.
There were many variables being initialized in pgss_store() before checking if the module was actually active, this would waste cpu processor if the module is disabled. To fix that, declare variables and initialize them only after check that pg_stat_monitor is active.pull/115/head
parent
a93ba37ac3
commit
fc9e630497
|
@ -1486,37 +1486,44 @@ pgss_store(uint64 queryid,
|
||||||
JumbleState *jstate,
|
JumbleState *jstate,
|
||||||
pgssStoreKind kind)
|
pgssStoreKind kind)
|
||||||
{
|
{
|
||||||
pgssEntry *entry;
|
pgssEntry *entry;
|
||||||
pgssSharedState *pgss = pgsm_get_ss();
|
pgssSharedState *pgss = pgsm_get_ss();
|
||||||
char application_name[APPLICATIONNAME_LEN];
|
char application_name[APPLICATIONNAME_LEN];
|
||||||
int application_name_len = pg_get_application_name(application_name);
|
int application_name_len;
|
||||||
bool reset = false;
|
bool reset = false;
|
||||||
uint64 bucketid;
|
uint64 bucketid;
|
||||||
uint64 prev_bucket_id;
|
uint64 prev_bucket_id;
|
||||||
uint64 userid;
|
uint64 userid;
|
||||||
int con;
|
int con;
|
||||||
uint64 dbid = MyDatabaseId;
|
uint64 dbid;
|
||||||
uint64 ip = pg_get_client_addr();
|
uint64 ip;
|
||||||
uint64 planid = plan_info ? plan_info->planid: 0;
|
uint64 planid;
|
||||||
uint64 appid = djb2_hash((unsigned char *)application_name, application_name_len);
|
uint64 appid;
|
||||||
char comments[512] = "";
|
char comments[512] = "";
|
||||||
bool out_of_memory = false;
|
bool out_of_memory = false;
|
||||||
|
|
||||||
/* Monitoring is disabled */
|
/* Monitoring is disabled */
|
||||||
if (!PGSM_ENABLED)
|
if (!PGSM_ENABLED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Assert(query != NULL);
|
|
||||||
if (kind == PGSS_ERROR)
|
|
||||||
GetUserIdAndSecContext((unsigned int *)&userid, &con);
|
|
||||||
else
|
|
||||||
userid = GetUserId();
|
|
||||||
|
|
||||||
extract_query_comments(query, comments, sizeof(comments));
|
|
||||||
|
|
||||||
/* Safety check... */
|
/* Safety check... */
|
||||||
if (!IsSystemInitialized() || !pgss_qbuf[pg_atomic_read_u64(&pgss->current_wbucket)])
|
if (!IsSystemInitialized() || !pgss_qbuf[pg_atomic_read_u64(&pgss->current_wbucket)])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Assert(query != NULL);
|
||||||
|
if (kind == PGSS_ERROR)
|
||||||
|
GetUserIdAndSecContext((unsigned int *)&userid, &con);
|
||||||
|
else
|
||||||
|
userid = GetUserId();
|
||||||
|
|
||||||
|
dbid = MyDatabaseId;
|
||||||
|
application_name_len = pg_get_application_name(application_name);
|
||||||
|
ip = pg_get_client_addr();
|
||||||
|
planid = plan_info ? plan_info->planid: 0;
|
||||||
|
appid = djb2_hash((unsigned char *)application_name, application_name_len);
|
||||||
|
|
||||||
|
extract_query_comments(query, comments, sizeof(comments));
|
||||||
|
|
||||||
prev_bucket_id = pg_atomic_read_u64(&pgss->current_wbucket);
|
prev_bucket_id = pg_atomic_read_u64(&pgss->current_wbucket);
|
||||||
bucketid = get_next_wbucket(pgss);
|
bucketid = get_next_wbucket(pgss);
|
||||||
|
|
||||||
|
@ -1717,7 +1724,6 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo,
|
||||||
if (query_entry == NULL)
|
if (query_entry == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
if (read_query(buf, bucketid, queryid, query_txt) == 0)
|
if (read_query(buf, bucketid, queryid, query_txt) == 0)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
|
|
Loading…
Reference in New Issue