]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Simplify truncate_query_log() callers
authorFujii Masao <fujii@postgresql.org>
Thu, 9 Jul 2026 23:37:59 +0000 (08:37 +0900)
committerFujii Masao <fujii@postgresql.org>
Thu, 9 Jul 2026 23:37:59 +0000 (08:37 +0900)
truncate_query_log() returns NULL when statement truncation is
disabled or the supplied query does not need to be truncated. Therefore,
callers do not need to check log_statement_max_length before calling
it.

Remove the redundant checks and let truncate_query_log() make the
decision in one place. This simplifies the statement and duration
logging code without changing its behavior.

Author: Jim Jones <jim.jones@uni-muenster.de>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwFOV+7nOdfoO=kfVH=-fRA9aQE1YcHHLYty3nfQ9rQ4RA@mail.gmail.com

src/backend/tcop/postgres.c

index 2d1c22c4fbd01fe29c7691d9f2b9549d2a8a98d4..b6bdfe213feec22f20200953463c0f4d32483d22 100644 (file)
@@ -1085,10 +1085,7 @@ exec_simple_query(const char *query_string)
        /* Log immediately if dictated by log_statement */
        if (check_log_statement(parsetree_list))
        {
-               char       *truncated_stmt = NULL;
-
-               if (log_statement_max_length >= 0)
-                       truncated_stmt = truncate_query_log(query_string);
+               char       *truncated_stmt = truncate_query_log(query_string);
 
                ereport(LOG,
                                (errmsg("statement: %s",
@@ -1392,10 +1389,7 @@ exec_simple_query(const char *query_string)
                        break;
                case 2:
                        {
-                               char       *truncated_stmt = NULL;
-
-                               if (log_statement_max_length >= 0)
-                                       truncated_stmt = truncate_query_log(query_string);
+                               char       *truncated_stmt = truncate_query_log(query_string);
 
                                ereport(LOG,
                                                (errmsg("duration: %s ms  statement: %s",
@@ -1638,10 +1632,7 @@ exec_parse_message(const char *query_string,     /* string to execute */
                        break;
                case 2:
                        {
-                               char       *truncated_stmt = NULL;
-
-                               if (log_statement_max_length >= 0)
-                                       truncated_stmt = truncate_query_log(query_string);
+                               char       *truncated_stmt = truncate_query_log(query_string);
 
                                ereport(LOG,
                                                (errmsg("duration: %s ms  parse %s: %s",
@@ -2125,10 +2116,7 @@ exec_bind_message(StringInfo input_message)
                        break;
                case 2:
                        {
-                               char       *truncated_stmt = NULL;
-
-                               if (log_statement_max_length >= 0)
-                                       truncated_stmt = truncate_query_log(psrc->query_string);
+                               char       *truncated_stmt = truncate_query_log(psrc->query_string);
 
                                ereport(LOG,
                                                (errmsg("duration: %s ms  bind %s%s%s: %s",
@@ -2282,10 +2270,7 @@ exec_execute_message(const char *portal_name, long max_rows)
        /* Log immediately if dictated by log_statement */
        if (check_log_statement(portal->stmts))
        {
-               char       *truncated_source = NULL;
-
-               if (log_statement_max_length >= 0)
-                       truncated_source = truncate_query_log(sourceText);
+               char       *truncated_source = truncate_query_log(sourceText);
 
                ereport(LOG,
                                (errmsg("%s %s%s%s: %s",
@@ -2414,10 +2399,7 @@ exec_execute_message(const char *portal_name, long max_rows)
                        break;
                case 2:
                        {
-                               char       *truncated_source = NULL;
-
-                               if (log_statement_max_length >= 0)
-                                       truncated_source = truncate_query_log(sourceText);
+                               char       *truncated_source = truncate_query_log(sourceText);
 
                                ereport(LOG,
                                                (errmsg("duration: %s ms  %s %s%s%s: %s",