@@ -13,16 +13,19 @@ extern PgSQL_STMT_Manager *GloPgStmt;
1313
1414const int PS_GLOBAL_STATUS_FIELD_NUM = 8 ;
1515
16- static uint64_t stmt_compute_hash (const char *user,
17- const char *database, const char *query, unsigned int query_length, const Parse_Param_Types& param_types) {
16+ static uint64_t stmt_compute_hash_opts (const char *user,
17+ const char *database, const char *query, unsigned int query_length,
18+ const Parse_Param_Types& param_types,
19+ bool strip_query_comments
20+ ) {
1821 // two random seperators
1922 static const char DELIM1[] = " -ZiODNjvcNHTFaARXoqqSPDqQe-" ;
2023 static const char DELIM2[] = " -aSfpWDoswfuRsJXqZKfcelzCL-" ;
2124 static const char DELIM3[] = " -rQkhRVXdvgVYsmiqZCMikjKmP-" ;
2225
23- // NOSONAR: strlen is safe here
26+ // NOSONAR: strlen is safe here
2427 size_t user_length = strlen (user); // NOSONAR
25- // NOSONAR: strlen is safe here
28+ // NOSONAR: strlen is safe here
2629 size_t database_length = strlen (database); // NOSONAR
2730 size_t delim1_length = sizeof (DELIM1) - 1 ;
2831 size_t delim2_length = sizeof (DELIM2) - 1 ;
@@ -47,7 +50,22 @@ static uint64_t stmt_compute_hash(const char *user,
4750 memcpy (buf + l, DELIM1, delim1_length); l += delim1_length; // write delimiter1
4851 memcpy (buf + l, database, database_length); l += database_length; // write database
4952 memcpy (buf + l, DELIM2, delim2_length); l += delim2_length; // write delimiter2
50- memcpy (buf + l, query, query_length); l += query_length; // write query
53+
54+ // write query
55+ char *nquery = NULL ;
56+ if (strip_query_comments) {
57+ char *nquery = mysql_query_strip_comments ((char *)query, query_length, false );
58+ if (nquery != NULL ) {
59+ query = nquery;
60+ query_length = strlen (nquery);
61+ }
62+ }
63+ memcpy (buf + l, query, query_length);
64+ l += query_length;
65+ if (nquery != NULL ) {
66+ free (nquery);
67+ }
68+
5169 if (!param_types.empty ()) {
5270 uint16_t size = param_types.size ();
5371 memcpy (buf + l, DELIM3, delim3_length); l += delim3_length; // write delimiter3
@@ -58,6 +76,15 @@ static uint64_t stmt_compute_hash(const char *user,
5876 return hash;
5977}
6078
79+ inline static uint64_t stmt_compute_hash (const char *user,
80+ const char *database, const char *query, unsigned int query_length,
81+ const Parse_Param_Types& param_types
82+ ) {
83+ return stmt_compute_hash_opts (
84+ user, database, query, query_length, param_types,
85+ !pgsql_thread___query_digests_keep_comment);
86+ }
87+
6188void PgSQL_STMT_Global_info::compute_hash () {
6289 hash = stmt_compute_hash (username, dbname, query,
6390 query_length, parse_param_types);
@@ -80,7 +107,7 @@ PgSQL_STMT_Global_info::PgSQL_STMT_Global_info(uint64_t id, const char *_user, c
80107 first_comment = _first_comment ? strdup (_first_comment) : nullptr ;
81108 parse_param_types = std::move (_ppt);
82109 PgQueryCmd = PGSQL_QUERY__UNINITIALIZED;
83-
110+
84111 if (_h) {
85112 hash = _h;
86113 } else {
0 commit comments