diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 3db38ea1c..4a3289cb0 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -660,6 +660,7 @@ sync_config_strategy|enum|all_node,only_sync_node,none_node|NULL|Synchronization time_to_target_rpo|int|0,3600|NULL|NULL| disable_memory_protect|bool|0,0|NULL|NULL| unique_sql_clean_ratio|real|0,0.2|NULL|NULL| +enable_auto_clean_unique_sql|bool|0,0|NULL|NULL| [cmserver] log_dir|string|0,0|NULL|NULL| log_file_size|int|0,2047|MB|NULL| diff --git a/src/bin/gs_guc/cluster_guc.cpp b/src/bin/gs_guc/cluster_guc.cpp index f1456dbb2..971581aa7 100644 --- a/src/bin/gs_guc/cluster_guc.cpp +++ b/src/bin/gs_guc/cluster_guc.cpp @@ -1778,7 +1778,6 @@ char* get_AZ_value(const char* value, const char* data_dir) char delims[] = ","; char* vptr = NULL; char emptyvalue[] = "''"; - int resultStatus = 0; bool isNodeName = false; if (az1 != NULL) { diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index 4b41fb0c7..1e9cd5658 100644 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -174,6 +174,8 @@ #define CONFIG_EXEC_PARAMS_NEW "global/config_exec_params.new" #endif +#define DEFAULT_CLEAN_RATIO 0.1 + /* upper limit for GUC variables measured in kilobytes of memory */ /* note that various places assume the byte size fits in a "long" variable */ #if SIZEOF_SIZE_T > 4 && SIZEOF_LONG > 4 @@ -548,6 +550,10 @@ static bool logging_module_check(char** newval, void** extra, GucSource source); static void logging_module_guc_assign(const char* newval, void* extra); static void plog_merge_age_assign(int newval, void* extra); +#ifndef ENABLE_MULTIPLE_NODES +static bool CheckUniqueSqlCleanRatio(double* newval, void** extra, GucSource source); +#endif + /* Inplace Upgrade GUC hooks */ static bool check_is_upgrade(bool* newval, void** extra, GucSource source); static void assign_is_inplace_upgrade(const bool newval, void* extra); @@ -3267,6 +3273,17 @@ static void InitConfigureNamesBool() NULL, NULL, NULL}, + + {{"enable_auto_clean_unique_sql", + PGC_POSTMASTER, + INSTRUMENTS_OPTIONS, + gettext_noop("Enable auto clean unique sql entry when the UniquesQl hash table is full."), + NULL}, + &g_instance.attr.attr_common.enable_auto_clean_unique_sql, + false, + NULL, + NULL, + NULL}, #endif {{"enable_partition_opfusion", PGC_USERSET, QUERY_TUNING_METHOD, @@ -6925,17 +6942,17 @@ static void InitConfigureNamesReal() { #ifndef ENABLE_MULTIPLE_NODES {{"unique_sql_clean_ratio", - PGC_POSTMASTER, + PGC_SIGHUP, INSTRUMENTS_OPTIONS, gettext_noop("The percentage of the UniquesQl hash table that will be " "automatically eliminated when the UniquesQl hash table " - "is full. 0 means that auto-eliminate is not enabled."), + "is full."), NULL}, - &g_instance.attr.attr_common.unique_sql_clean_ratio, - 0, + &u_sess->attr.attr_common.unique_sql_clean_ratio, + DEFAULT_CLEAN_RATIO, 0, 0.2, - NULL, + CheckUniqueSqlCleanRatio, NULL, NULL}, #endif @@ -19165,6 +19182,21 @@ static void plog_merge_age_assign(int newval, void* extra) t_thrd.log_cxt.plog_msg_switch_tm.tv_usec = (newval - MS_PER_S * t_thrd.log_cxt.plog_msg_switch_tm.tv_sec) * 1000; } +#ifndef ENABLE_MULTIPLE_NODES +static bool CheckUniqueSqlCleanRatio(double* newval, void** extra, GucSource source) +{ + if (g_instance.attr.attr_common.enable_auto_clean_unique_sql && *newval == 0) { + ereport(WARNING, + (errmsg("Can't set unique_sql_clean_ratio to 0 when enable_auto_clean_unique_sql is true. " + "Reset it's value to default(%lf). If you want to disable auto clean unique sql, " + "please set enable_auto_clean_unique_sql to false.", + DEFAULT_CLEAN_RATIO))); + *newval = DEFAULT_CLEAN_RATIO; + } + return true; +} +#endif + /* ------------------------------------------------------------ */ /* GUC hooks for inplace/grey upgrade */ /* ------------------------------------------------------------ */ diff --git a/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp b/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp index 22f79a44a..b1d4d7cef 100644 --- a/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp +++ b/src/gausskernel/cbb/instruments/unique_sql/instr_unique_sql.cpp @@ -679,7 +679,7 @@ void UpdateUniqueSQLStat(Query* query, const char* sql, int64 elapse_start_time, /* control unique sql number by instr_unique_sql_count. */ long totalCount = hash_get_num_entries(g_instance.stat_cxt.UniqueSQLHashtbl); if (totalCount >= u_sess->attr.attr_common.instr_unique_sql_count) { - if (g_instance.attr.attr_common.unique_sql_clean_ratio != 0) { + if (g_instance.attr.attr_common.enable_auto_clean_unique_sql) { if (!AutoRecycleUniqueSQLEntry()) { return; } @@ -1807,7 +1807,7 @@ static void SetLocalUniqueSQLId(List* query_list) /* store the normalized uniquesq text into u_sess->Unique_sql_cxt in stage B * or E of PBE, only if auto-cleanup is enabled */ - if (g_instance.attr.attr_common.unique_sql_clean_ratio != 0) { + if (g_instance.attr.attr_common.enable_auto_clean_unique_sql) { u_sess->unique_sql_cxt.unique_sql_text = query->unique_sql_text; } #endif @@ -2423,7 +2423,7 @@ static bool AutoRecycleUniqueSQLEntry() (errmodule(MOD_INSTR), errcode(ERRCODE_LOG), errmsg("[UniqueSQL] instr_unique_sql_count is too large, uniquesql auto-clean will not happen."))); return false; } - double ratio = g_instance.attr.attr_common.unique_sql_clean_ratio; + double ratio = u_sess->attr.attr_common.unique_sql_clean_ratio; int cleanCount = Max(int(ratio * instr_unique_sql_count + totalCount - instr_unique_sql_count), 1); /* get remove entry list */ KeyUpdatedtime* removeList = GetSortedEntryList(); diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index e70049ce0..ec67eb296 100644 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -3373,7 +3373,7 @@ static void exec_parse_message(const char* query_string, /* string to execute */ #ifndef ENABLE_MULTIPLE_NODES /* store normalized uniquesQl text into Query in P phase of PBE, only if auto-cleanup is enabled */ - if (is_unique_sql_enabled() && g_instance.attr.attr_common.unique_sql_clean_ratio != 0) { + if (is_unique_sql_enabled() && g_instance.attr.attr_common.enable_auto_clean_unique_sql) { query->unique_sql_text = FindCurrentUniqueSQL(); } #endif diff --git a/src/include/knl/knl_guc/knl_instance_attr_common.h b/src/include/knl/knl_guc/knl_instance_attr_common.h index 15e7a6042..0d6a915a2 100644 --- a/src/include/knl/knl_guc/knl_instance_attr_common.h +++ b/src/include/knl/knl_guc/knl_instance_attr_common.h @@ -94,7 +94,7 @@ typedef struct knl_instance_attr_common { #endif #ifndef ENABLE_MULTIPLE_NODES int sync_config_strategy; - double unique_sql_clean_ratio; + bool enable_auto_clean_unique_sql; #endif } knl_instance_attr_common; diff --git a/src/include/knl/knl_guc/knl_session_attr_common.h b/src/include/knl/knl_guc/knl_session_attr_common.h index 60becb840..88b77195d 100644 --- a/src/include/knl/knl_guc/knl_session_attr_common.h +++ b/src/include/knl/knl_guc/knl_session_attr_common.h @@ -172,6 +172,9 @@ typedef struct knl_session_attr_common { /* instrumentation guc parameters */ int instr_unique_sql_count; +#ifndef ENABLE_MULTIPLE_NODES + double unique_sql_clean_ratio; +#endif bool enable_instr_cpu_timer; int unique_sql_track_type; bool enable_instr_track_wait;