[Commits] 62021f3: MDEV-12070 - Introduce thd_query_safe() from MySQL 5.7

Sergey Vojtovich svoj at mariadb.org
Thu Jun 22 16:16:28 EEST 2017


revision-id: 62021f391a42c5577190aa43cb8ad91e56235b46 (mariadb-10.2.6-57-g62021f3)
parent(s): 557e1bd472612848a42e772c1fb6f8ed32ab33b4
committer: Sergey Vojtovich
timestamp: 2017-06-22 17:15:10 +0400
message:

MDEV-12070 - Introduce thd_query_safe() from MySQL 5.7

Merged relevant part of MySQL revision:
https://github.com/mysql/mysql-server/commit/565d20b44f24fcc855dc616164d87b03cfad10bc

---
 sql/sql_class.cc                      | 26 ++++++++++++++++++++++++++
 sql/sql_class.h                       |  1 +
 storage/innobase/handler/ha_innodb.cc | 17 +----------------
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index f8cf829..db65eb3 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -4529,6 +4529,32 @@ extern "C" LEX_STRING * thd_query_string (MYSQL_THD thd)
   return(&thd->query_string.string);
 }
 
+
+/**
+  Get the current query string for the thread.
+
+  @param thd     The MySQL internal thread pointer
+  @param buf     Buffer where the query string will be copied
+  @param buflen  Length of the buffer
+
+  @return Length of the query
+
+  @note This function is thread safe as the query string is
+        accessed under mutex protection and the string is copied
+        into the provided buffer. @see thd_query_string().
+*/
+
+extern "C" size_t thd_query_safe(MYSQL_THD thd, char *buf, size_t buflen)
+{
+  mysql_mutex_lock(&thd->LOCK_thd_data);
+  size_t len= MY_MIN(buflen - 1, thd->query_length());
+  memcpy(buf, thd->query(), len);
+  mysql_mutex_unlock(&thd->LOCK_thd_data);
+  buf[len]= '\0';
+  return len;
+}
+
+
 extern "C" int thd_slave_thread(const MYSQL_THD thd)
 {
   return(thd->slave_thread);
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 2d1bf8a..5a5ada9 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -154,6 +154,7 @@ extern bool volatile shutdown_in_progress;
 
 extern "C" LEX_STRING * thd_query_string (MYSQL_THD thd);
 extern "C" char **thd_query(MYSQL_THD thd);
+extern "C" size_t thd_query_safe(MYSQL_THD thd, char *buf, size_t buflen);
 
 /**
   @class CSET_STRING
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index a54176f..d8a4d8d 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -2462,22 +2462,7 @@ innobase_get_stmt_safe(
 	char*	buf,
 	size_t	buflen)
 {
-	LEX_STRING* stmt;
-	size_t length=0;
-
-	ut_ad(buflen > 1);
-
-	stmt =  thd ? thd_query_string(thd) : NULL;
-
-	if (stmt && stmt->str) {
-		length = stmt->length >= buflen ? buflen - 1 : stmt->length;
-		memcpy(buf, stmt->str, length);
-		buf[length]='\0';
-	} else {
-		buf[0]='\0';
-	}
-
-	return (length);
+	return thd_query_safe(thd, buf, buflen);
 }
 
 /**********************************************************************//**


More information about the commits mailing list