MySQL 8.0.39
Source Code Documentation
s_mysql_mysql_thd_attributes Struct Reference

THD Attributes service allows to obtain data associated with the THD object, which keeps various attributes of the user session. More...

#include <mysql_thd_attributes.h>

Public Attributes

mysql_service_status_t(* get )(THD *thd, const char *name, void *inout_pvalue)
 Get THD attribute. More...
 
mysql_service_status_t(* set )(THD *thd, const char *name, void *inout_pvalue)
 Set THD attribute. More...
 

Detailed Description

THD Attributes service allows to obtain data associated with the THD object, which keeps various attributes of the user session.

Currently, following attributes are supported:

  • Query Digest Text
  • Query Text
  • Host or IP
  • Schema

Initialization

The service can be instantiated using the registry service with the "mysql_thd_attributes" name.

svc("mysql_thd_attributes", registry);
if (svc.is_valid()) {
// The service is ready to be used
}
Wraps my_h_service struct conforming ABI into RAII C++ object with ability to cast to desired service...
Definition: my_service.h:35
const mysql_service_mysql_thd_attributes_t * mysql_thd_attributes
Definition: rewriter_plugin.cc:59
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
const mysql_service_registry_t * mysql_plugin_registry_acquire()
Returns a new reference to the "registry" service.
Definition: plugin_registry_service.cc:47

Query Digest Text

Query Digest represents converted SQL statement to normalized form. The code below demonstrates how query digest can be obtained from the service.

mysql_thd_attributes->get(m_thd, "query_digest",
reinterpret_cast<void *>(&str));
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
Definition: mysql_string_service.cc:59
mysql_service_status_t(* get)(THD *thd, const char *name, void *inout_pvalue)
Get THD attribute.
Definition: mysql_thd_attributes.h:127

The buffer can be fetched using the code below:

char buf[1024]; // buffer must be big enough to store the digest
mysql_string_converter->convert_to_buffer(str, buf, sizeof(buf), "utf8mb3");
Definition: buf0block_hint.cc:30

After the string content has been copied into another buffer, it must be destroyed:

mysql_string_factory->destroy(str);

Query Text

Query text represents complete SQL text currently being executed within a given session. The example code is identical to the one for Query Digest, the only difference is that attribute name "sql_text" should be used in this case.

Host or IP

Host or IP text contains host or IP (if host unavailable) belonging to a client associated with a given session. The example code is identical to the one for Query Digest, the only difference is that attribute name "host_or_ip" should be used in this case.

Schema

Schema text contains a name of database currently in use by a client associated with a given session. The example code is identical to the one for Query Digest, the only difference is that attribute name "schema" should be used in this case.

Member Data Documentation

◆ get

mysql_service_status_t(* s_mysql_mysql_thd_attributes::get) (THD *thd, const char *name, void *inout_pvalue)

Get THD attribute.

Currently, following attributes are supported:

  • Query Digest Text ("query_digest" of the returned my_h_string type)
  • Query Text ("sql_text" of the returned my_h_string type)
  • Host or IP ("host_or_ip" of the returned my_h_string type)
  • Schema ("schema" of the returned my_h_string type)
  • Is Upgrade Thread ("is_upgrade_thread" of the returned bool type)
  • Is Init File System Thread ("is_init_file_thread" of the returned bool type)
Parameters
thdSession THD object.
nameName of the attribute to be set.
[out]inout_pvalueIterator pointer.
Returns
Return values
FALSESucceeded.
TRUEFailed.

◆ set

mysql_service_status_t(* s_mysql_mysql_thd_attributes::set) (THD *thd, const char *name, void *inout_pvalue)

Set THD attribute.

Currently the implementation does not support setting of any attribute.

Parameters
thdSession THD object.
nameName of the attribute to be set.
[out]inout_pvalueIterator pointer.
Returns
The function always fail and return TRUE value.

The documentation for this struct was generated from the following file: