On 2024/10/16 18:52, Fujii Masao wrote:
On 2024/10/16 15:04, Yuto Sasaki (Fujitsu) wrote:
>Hmm, I'm not sure we want that, because if we do this, then
>ECPGget_sqlca() gets run with the debug_mutex held. In the original
>coding, it's run without the mutex.
Thank you for pointing that out. I agree with your observation. But there is
another room for improvement - we can avoid unnecessary calls to ECPGget_sqlca()
by moving just before mutex lock.
+1
PSA a patch.
The patch looks good to me.
I've attached the latest version of the patch, now including the commit log.
Unless there are any objections, I'll proceed with committing it.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
From 12636b9d33a6934985d226f556d88bac341a5715 Mon Sep 17 00:00:00 2001
From: Fujii Masao <fu...@postgresql.org>
Date: Fri, 18 Oct 2024 14:22:17 +0900
Subject: [PATCH v2] ecpg: Refactor ecpg_log() to skip unnecessary calls to
ECPGget_sqlca().
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: Fujii Masao
Discussion:
https://postgr.es/m/ty2pr01mb3628a85689649babc9a1c6c3c1...@ty2pr01mb3628.jpnprd01.prod.outlook.com
---
src/interfaces/ecpg/ecpglib/misc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/interfaces/ecpg/ecpglib/misc.c
b/src/interfaces/ecpg/ecpglib/misc.c
index 2ae989e3e5..06f788ea38 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -232,7 +232,7 @@ void
ecpg_log(const char *format,...)
{
va_list ap;
- struct sqlca_t *sqlca = ECPGget_sqlca();
+ struct sqlca_t *sqlca;
const char *intl_format;
int bufsize;
char *fmt;
@@ -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 */
--
2.46.2