Remove duplication definitions of NAMEDATALEN.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 20 Sep 2023 06:07:26 +0000 (15:07 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 20 Sep 2023 06:07:26 +0000 (15:07 +0900)
The definition for NAMEDATALEN is now in
src/include/pg_config_manual.h only.  Also replace POOL_NAMEDATALEN
with NAMEDATALEN in src/utils/pool_select_walker.c.

I tried to eliminate copying pool_config_manual.h from PostgreSQL but
it seems it is a little bit difficult to do that at this moment.
There are some definitions like pg_attribute_format_arg were added to
it.

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-August/004366.html

src/include/parser/pool_parser.h
src/include/pcp/libpcp_ext.h
src/include/pool.h
src/include/utils/pool_select_walker.h
src/protocol/pool_process_query.c
src/utils/pool_select_walker.c

index b63c021c9bd010a832695351f7f0b14e0ce6c234..b0045d3f0e092ed8fa0ff6aecbdbada48660fcf4 100644 (file)
@@ -2,7 +2,7 @@
 /*
  * $Header$
  *
- * Copyright (c) 2006-2015, pgpool Global Development Group
+ * Copyright (c) 2006-2023, pgpool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -30,16 +30,6 @@ extern int   server_version_num;
 /* from include/postgresql_ext.h */
 #define InvalidOid             ((Oid) 0)
 
-/* from include/pg_config_manual.h */
-/*
- * NAMEDATALEN is the max length for system identifiers (e.g. table names,
- * attribute names, function names, etc).  It must be a multiple of
- * sizeof(int) (typically 4).
- *
- * NOTE that databases with different NAMEDATALEN's cannot interoperate!
- */
-#define NAMEDATALEN 64
-
 /* from include/c.h */
 
 /*
index 7d2ab70db9f32133a1ac95d9d1251ab9a7492c04..3c5f41ebfe6a9216c837c37a7e62179f59c34973 100644 (file)
@@ -4,7 +4,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2022     PgPool Global Development Group
+ * Copyright (c) 2003-2023     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -29,6 +29,8 @@
 #include <signal.h>
 #include <stdio.h>
 
+#include "pg_config_manual.h"
+
 /*
  * startup packet definitions (v2) stolen from PostgreSQL
  */
@@ -49,7 +51,6 @@
 #define MAX_CONNECTION_SLOTS MAX_NUM_BACKENDS
 #define MAX_DB_HOST_NAMELEN     MAX_FDQN_HOSTNAME_LEN
 #define MAX_PATH_LENGTH 256
-#define NAMEDATALEN 64
 
 typedef enum
 {
index 50cf63d703dc9d683bebeef0a2bdf60b80b8d409..56ddbeb145f521079895549f6c8d658ea7670ecf 100644 (file)
 #define POOLKEYFILE    ".pgpoolkey"
 #define POOLKEYFILEENV "PGPOOLKEYFILE"
 
-/*
- * Brought from PostgreSQL's pg_config_manual.h.
- *
- * Maximum length for identifiers (e.g. table names, column names,
- * function names).  Names actually are limited to one less byte than this,
- * because the length must include a trailing zero byte.
- *
- * Please note that in version 2 protocol, maximum user name length is
- * SM_USER, which is 32.
- */
-#define NAMEDATALEN 64
-
-/* configuration file name */
 #define POOL_CONF_FILE_NAME "pgpool.conf"
 
 /* PCP user/password file name */
index c04d2e98648c5bc7b4164772c8565fd95896a69b..9a0e105a2b7c401a6c8ad9d42bef96d9f9265ee4 100644 (file)
@@ -6,7 +6,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2012     PgPool Global Development Group
+ * Copyright (c) 2003-2023     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -32,7 +32,6 @@
 #include "parser/makefuncs.h"
 
 #define POOL_MAX_SELECT_OIDS 128
-#define POOL_NAMEDATALEN 64            /* from NAMEDATALEN of PostgreSQL */
 
 typedef struct
 {
@@ -51,7 +50,7 @@ typedef struct
                                                                                                         * SHARE/UPDATE */
        int                     num_oids;               /* number of oids */
        int                     table_oids[POOL_MAX_SELECT_OIDS];       /* table oids */
-       char            table_names[POOL_MAX_SELECT_OIDS][POOL_NAMEDATALEN];    /* table names */
+       char            table_names[POOL_MAX_SELECT_OIDS][NAMEDATALEN]; /* table names */
 }                      SelectContext;
 
 extern int     pool_get_terminate_backend_pid(Node *node);
index 872a5d85555314adffe110d0b8b0cfcf882a934e..f6749aa8a33b03493e73a25f4803b8356fc30693 100644 (file)
@@ -42,6 +42,7 @@
 
 #include "pool.h"
 #include "pool_config.h"
+#include "pg_config_manual.h"
 #include "rewrite/pool_timestamp.h"
 #include "main/pool_internal_comms.h"
 #include "protocol/pool_process_query.h"
index bec2b67ce7454c03dd5d5e068a0c4d730ae13e97..27e745ba473d19a50f91f92aff17b4eb5c2aa94c 100644 (file)
@@ -1321,7 +1321,7 @@ select_table_walker(Node *node, void *context)
                        num_oids = ctx->num_oids++;
 
                        ctx->table_oids[num_oids] = oid;
-                       strlcpy(ctx->table_names[num_oids], table, POOL_NAMEDATALEN);
+                       strlcpy(ctx->table_names[num_oids], table, NAMEDATALEN);
 
                        ereport(DEBUG1,
                                        (errmsg("extracting table oids from SELECT statement"),
@@ -1384,11 +1384,11 @@ make_function_name_from_funccall(FuncCall *fcall)
 {
        /*
         * Function name. Max size is calculated as follows: schema
-        * name(POOL_NAMEDATALEN byte) + quotation marks for schema name(2 byte) +
-        * period(1 byte) + table name (POOL_NAMEDATALEN byte) + quotation marks
+        * name(NAMEDATALEN byte) + quotation marks for schema name(2 byte) +
+        * period(1 byte) + table name (NAMEDATALEN byte) + quotation marks
         * for table name(2 byte) + NULL(1 byte)
         */
-       static char funcname[POOL_NAMEDATALEN * 2 + 1 + 2 * 2 + 1];
+       static char funcname[NAMEDATALEN * 2 + 1 + 2 * 2 + 1];
        List       *names;
 
        if(fcall == NULL)
@@ -1405,29 +1405,29 @@ make_function_name_from_funccall(FuncCall *fcall)
        {
                case 1:
                        strcat(funcname, "\"");
-                       strncat(funcname, strVal(linitial(names)), POOL_NAMEDATALEN);
+                       strncat(funcname, strVal(linitial(names)), NAMEDATALEN);
                        strcat(funcname, "\"");
                        break;
                case 2:
                        strcat(funcname, "\"");
-                       strncat(funcname, strVal(linitial(names)), POOL_NAMEDATALEN);
+                       strncat(funcname, strVal(linitial(names)), NAMEDATALEN);
                        strcat(funcname, "\"");
 
                        strcat(funcname, ".");
 
                        strcat(funcname, "\"");
-                       strncat(funcname, strVal(lsecond(names)), POOL_NAMEDATALEN);
+                       strncat(funcname, strVal(lsecond(names)), NAMEDATALEN);
                        strcat(funcname, "\"");
                        break;
                case 3:
                        strcat(funcname, "\"");
-                       strncat(funcname, strVal(lsecond(names)), POOL_NAMEDATALEN);
+                       strncat(funcname, strVal(lsecond(names)), NAMEDATALEN);
                        strcat(funcname, "\"");
 
                        strcat(funcname, ".");
 
                        strcat(funcname, "\"");
-                       strncat(funcname, strVal(lthird(names)), POOL_NAMEDATALEN);
+                       strncat(funcname, strVal(lthird(names)), NAMEDATALEN);
                        strcat(funcname, "\"");
 
                        break;
@@ -1453,11 +1453,11 @@ make_table_name_from_rangevar(RangeVar *rangevar)
 {
        /*
         * Table name. Max size is calculated as follows: schema
-        * name(POOL_NAMEDATALEN byte) + quotation marks for schema name(2 byte) +
-        * period(1 byte) + table name (POOL_NAMEDATALEN byte) + quotation marks
+        * name(NAMEDATALEN byte) + quotation marks for schema name(2 byte) +
+        * period(1 byte) + table name (NAMEDATALEN byte) + quotation marks
         * for table name(2 byte) + NULL(1 byte)
         */
-       static char tablename[POOL_NAMEDATALEN * 2 + 1 + 2 * 2 + 1];
+       static char tablename[NAMEDATALEN * 2 + 1 + 2 * 2 + 1];
 
        if (rangevar == NULL)
        {
@@ -1479,7 +1479,7 @@ make_table_name_from_rangevar(RangeVar *rangevar)
        if (rangevar->schemaname)
        {
                strcat(tablename, "\"");
-               strncat(tablename, rangevar->schemaname, POOL_NAMEDATALEN);
+               strncat(tablename, rangevar->schemaname, NAMEDATALEN);
                strcat(tablename, "\"");
                strcat(tablename, ".");
        }
@@ -1493,7 +1493,7 @@ make_table_name_from_rangevar(RangeVar *rangevar)
        }
 
        strcat(tablename, "\"");
-       strncat(tablename, rangevar->relname, POOL_NAMEDATALEN);
+       strncat(tablename, rangevar->relname, NAMEDATALEN);
        strcat(tablename, "\"");
 
        ereport(DEBUG1,