ecpg: Refactor ecpg_log() to skip unnecessary calls to ECPGget_sqlca().
authorFujii Masao <[email protected]>
Tue, 22 Oct 2024 14:56:37 +0000 (23:56 +0900)
committerFujii Masao <[email protected]>
Tue, 22 Oct 2024 14:57:35 +0000 (23:57 +0900)
Previously, ecpg_log() always called ECPGget_sqlca() to retrieve sqlca,
even though it was only needed for debug logging. This commit updates
ecpg_log() to call ECPGget_sqlca() only when debug logging is enabled.

Author: Yuto Sasaki
Reviewed-by: Alvaro Herrera, Tom Lane, Fujii Masao
Discussion: https://postgr.es/m/TY2PR01MB3628A85689649BABC9A1C6C3C1782@TY2PR01MB3628.jpnprd01.prod.outlook.com

src/interfaces/ecpg/ecpglib/misc.c

index 2ae989e3e5d8294bc1f8492e8b08978c392dad27..8b38c3eccfde01d49ce6d09ee26f47ba0113ae7c 100644 (file)
@@ -232,10 +232,10 @@ void
 ecpg_log(const char *format,...)
 {
    va_list     ap;
-   struct sqlca_t *sqlca = ECPGget_sqlca();
    const char *intl_format;
    int         bufsize;
    char       *fmt;
+   struct sqlca_t *sqlca;
 
    /*
     * For performance reasons, inspect simple_debug without taking the mutex.
@@ -262,6 +262,8 @@ ecpg_log(const char *format,...)
    else
        snprintf(fmt, bufsize, "[%d]: %s", (int) getpid(), intl_format);
 
+   sqlca = ECPGget_sqlca();
+
    pthread_mutex_lock(&debug_mutex);
 
    /* Now that we hold the mutex, recheck simple_debug */