From 653105b7108f5eef8424d36dd80d19297030c9cc Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Wed, 20 Sep 2023 15:07:26 +0900 Subject: [PATCH] Remove duplication definitions of NAMEDATALEN. 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 | 12 +---------- src/include/pcp/libpcp_ext.h | 5 +++-- src/include/pool.h | 13 ------------ src/include/utils/pool_select_walker.h | 5 ++--- src/protocol/pool_process_query.c | 1 + src/utils/pool_select_walker.c | 28 +++++++++++++------------- 6 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/include/parser/pool_parser.h b/src/include/parser/pool_parser.h index b63c021c9..b0045d3f0 100644 --- a/src/include/parser/pool_parser.h +++ b/src/include/parser/pool_parser.h @@ -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 */ /* diff --git a/src/include/pcp/libpcp_ext.h b/src/include/pcp/libpcp_ext.h index a6d35b887..29e299995 100644 --- a/src/include/pcp/libpcp_ext.h +++ b/src/include/pcp/libpcp_ext.h @@ -4,7 +4,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2021 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 #include +#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 { diff --git a/src/include/pool.h b/src/include/pool.h index 8f695b7ed..b6a388225 100644 --- a/src/include/pool.h +++ b/src/include/pool.h @@ -47,19 +47,6 @@ #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 */ diff --git a/src/include/utils/pool_select_walker.h b/src/include/utils/pool_select_walker.h index eaa0a6fea..53fdb89b8 100644 --- a/src/include/utils/pool_select_walker.h +++ b/src/include/utils/pool_select_walker.h @@ -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); diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c index 5082d2f31..e088a515e 100644 --- a/src/protocol/pool_process_query.c +++ b/src/protocol/pool_process_query.c @@ -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" diff --git a/src/utils/pool_select_walker.c b/src/utils/pool_select_walker.c index 7a64c7899..b8302d269 100644 --- a/src/utils/pool_select_walker.c +++ b/src/utils/pool_select_walker.c @@ -1314,7 +1314,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"), @@ -1377,11 +1377,11 @@ make_function_name_from_funccall(FuncCall *fcall) { /* * Function name. Max size is calculated as follows: schema - * name(POOL_NAMEDATALEN byte) + quotation marks for schmea 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) @@ -1398,29 +1398,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; @@ -1446,11 +1446,11 @@ make_table_name_from_rangevar(RangeVar *rangevar) { /* * Table name. Max size is calculated as follows: schema - * name(POOL_NAMEDATALEN byte) + quotation marks for schmea 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) { @@ -1472,7 +1472,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, "."); } @@ -1486,7 +1486,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, -- 2.39.5