From 3d9f40d22a372d8ce7b2d052dbb23c8a0c160f48 Mon Sep 17 00:00:00 2001 From: Gokhan Gulbiz Date: Thu, 23 Mar 2023 10:20:50 +0300 Subject: [PATCH 1/3] Indent --- src/backend/distributed/utils/attribute.c | 58 ++++++++++++----------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/src/backend/distributed/utils/attribute.c b/src/backend/distributed/utils/attribute.c index f2d3fc6a2..b6c4e8426 100644 --- a/src/backend/distributed/utils/attribute.c +++ b/src/backend/distributed/utils/attribute.c @@ -611,42 +611,43 @@ MultiTenantMonitorshmemSize(void) static char * ExtractTopComment(const char *inputString) { - int commentCharsLength = 2; - int inputStringLen = strlen(inputString); - if (inputStringLen < commentCharsLength) - { - return NULL; - } + int commentCharsLength = 2; + int inputStringLen = strlen(inputString); + if (inputStringLen < commentCharsLength) + { + return NULL; + } - const char *commentStartChars = "/*"; - const char *commentEndChars = "*/"; + const char *commentStartChars = "/*"; + const char *commentEndChars = "*/"; - /* If query doesn't start with a comment, return NULL */ - if (strstr(inputString, commentStartChars) != inputString) - { - return NULL; - } + /* If query doesn't start with a comment, return NULL */ + if (strstr(inputString, commentStartChars) != inputString) + { + return NULL; + } - StringInfo commentData = makeStringInfo(); + StringInfo commentData = makeStringInfo(); - /* Skip the comment start characters */ - const char *commentStart = inputString + commentCharsLength; + /* Skip the comment start characters */ + const char *commentStart = inputString + commentCharsLength; - /* Find the first comment end character */ - const char *commentEnd = strstr(commentStart, commentEndChars); - if (commentEnd == NULL) - { - return NULL; - } + /* Find the first comment end character */ + const char *commentEnd = strstr(commentStart, commentEndChars); + if (commentEnd == NULL) + { + return NULL; + } - /* Append the comment to the StringInfo buffer */ - int commentLength = commentEnd - commentStart; - appendStringInfo(commentData, "%.*s", commentLength, commentStart); + /* Append the comment to the StringInfo buffer */ + int commentLength = commentEnd - commentStart; + appendStringInfo(commentData, "%.*s", commentLength, commentStart); - /* Return the extracted comment */ - return commentData->data; + /* Return the extracted comment */ + return commentData->data; } + /* EscapeCommentChars adds a backslash before each occurrence of '*' or '/' in the input string */ static char * EscapeCommentChars(const char *str) @@ -663,11 +664,12 @@ EscapeCommentChars(const char *str) } appendStringInfoChar(escapedString, str[originalStringIndex]); - } + } return escapedString->data; } + /* UnescapeCommentChars removes the backslash that precedes '*' or '/' in the input string. */ static char * UnescapeCommentChars(const char *str) From ad91298568d9ef0cef41e5f677d0aad6f483288a Mon Sep 17 00:00:00 2001 From: Gokhan Gulbiz Date: Thu, 23 Mar 2023 11:10:29 +0300 Subject: [PATCH 2/3] Increase citus.stats_tenants_limit to 10 --- src/test/regress/pg_regress_multi.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/regress/pg_regress_multi.pl b/src/test/regress/pg_regress_multi.pl index b003e1663..2707dc38a 100755 --- a/src/test/regress/pg_regress_multi.pl +++ b/src/test/regress/pg_regress_multi.pl @@ -485,7 +485,7 @@ push(@pgOptions, "citus.explain_analyze_sort_method='taskId'"); push(@pgOptions, "citus.enable_manual_changes_to_shards=on"); push(@pgOptions, "citus.allow_unsafe_locks_from_workers=on"); push(@pgOptions, "citus.stat_statements_track = 'all'"); -push(@pgOptions, "citus.stats_tenants_limit = 2"); +push(@pgOptions, "citus.stats_tenants_limit = 10"); # Some tests look at shards in pg_class, make sure we can usually see them: push(@pgOptions, "citus.show_shards_for_app_name_prefixes='pg_regress'"); From 7dfe0c7659ddbd8ccbf925808c625fe1d64ca24b Mon Sep 17 00:00:00 2001 From: Gokhan Gulbiz Date: Thu, 23 Mar 2023 11:12:16 +0300 Subject: [PATCH 3/3] Test special and multibyte characters in tenant attribute --- .../regress/expected/citus_stats_tenants.out | 105 +++++++++++++++++- src/test/regress/sql/citus_stats_tenants.sql | 23 ++++ 2 files changed, 125 insertions(+), 3 deletions(-) diff --git a/src/test/regress/expected/citus_stats_tenants.out b/src/test/regress/expected/citus_stats_tenants.out index 5856bd819..becbfdd27 100644 --- a/src/test/regress/expected/citus_stats_tenants.out +++ b/src/test/regress/expected/citus_stats_tenants.out @@ -61,7 +61,8 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q --------------------------------------------------------------------- 2 | 0 | 0 | 1 | 0 3 | 0 | 0 | 1 | 0 -(2 rows) + 4 | 0 | 0 | 1 | 0 +(3 rows) \c - - - :master_port SET search_path TO citus_stats_tenants; @@ -107,7 +108,8 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q --------------------------------------------------------------------- 2 | 1 | 0 | 2 | 0 3 | 0 | 0 | 1 | 0 -(2 rows) + 4 | 0 | 0 | 1 | 0 +(3 rows) \c - - - :master_port SELECT pg_sleep (3); @@ -130,7 +132,8 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q --------------------------------------------------------------------- 2 | 0 | 1 | 0 | 2 3 | 0 | 0 | 0 | 1 -(2 rows) + 4 | 0 | 0 | 0 | 1 +(3 rows) \c - - - :master_port SET search_path TO citus_stats_tenants; @@ -291,6 +294,102 @@ SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tena bcde | 3 | 3000000000 2 | 1 | 2000000000 3 | 1 | 1500000000 + 4 | 1 | 1500000000 + cdef | 1 | 1000000000 +(6 rows) + +\c - - - :master_port +SET search_path TO citus_stats_tenants; +-- test special and multibyte characters in tenant attribute +SELECT result FROM run_command_on_all_nodes('SELECT clean_citus_stats_tenants()'); + result +--------------------------------------------------------------------- + + + +(3 rows) + +TRUNCATE TABLE dist_tbl_text; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/bcde'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/*bcde'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b*cde'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b*c/de'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'b/*//cde'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b/*/cde'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b/**/cde'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*/'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc'; + ?column? +--------------------------------------------------------------------- + t +(1 row) + +\c - - - :worker_1_port +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period +--------------------------------------------------------------------- + /*bcde | 1 | 0 | 1 | 0 + /b*cde | 1 | 0 | 1 | 0 + /b/**/cde | 1 | 0 | 1 | 0 + /b/*/cde | 1 | 0 | 1 | 0 + b/*//cde | 1 | 0 | 1 | 0 + bcde*/ | 1 | 0 | 1 | 0 +(6 rows) + +\c - - - :worker_2_port +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; + tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period +--------------------------------------------------------------------- + /b*c/de | 1 | 0 | 1 | 0 + /bcde | 1 | 0 | 1 | 0 + äbc | 1 | 0 | 1 | 0 + bcde* | 1 | 0 | 1 | 0 (4 rows) \c - - - :master_port diff --git a/src/test/regress/sql/citus_stats_tenants.sql b/src/test/regress/sql/citus_stats_tenants.sql index 7c7e1ed4c..1e52b7705 100644 --- a/src/test/regress/sql/citus_stats_tenants.sql +++ b/src/test/regress/sql/citus_stats_tenants.sql @@ -106,6 +106,29 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'cdef'; \c - - - :worker_2_port SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tenants(true) ORDER BY score DESC; + +\c - - - :master_port +SET search_path TO citus_stats_tenants; + +-- test special and multibyte characters in tenant attribute +SELECT result FROM run_command_on_all_nodes('SELECT clean_citus_stats_tenants()'); +TRUNCATE TABLE dist_tbl_text; + +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/bcde'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/*bcde'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b*cde'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b*c/de'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'b/*//cde'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b/*/cde'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/b/**/cde'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*/'; +SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc'; + +\c - - - :worker_1_port +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; +\c - - - :worker_2_port +SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; \c - - - :master_port SET client_min_messages TO ERROR;