|
|
|
|
@ -4,8 +4,38 @@
|
|
|
|
|
#include "proxysql.h"
|
|
|
|
|
#include "cpp.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
One of the main challenge in handling prepared statement (PS) is that a single
|
|
|
|
|
PS could be executed on multiple backends, and on each backend it could have a
|
|
|
|
|
different stmt_id.
|
|
|
|
|
For this reason ProxySQL returns to the client a stmt_id generated by the proxy
|
|
|
|
|
itself, and internally maps client's stmt_id with the backend stmt_id.
|
|
|
|
|
|
|
|
|
|
// class MySQL_STMTs_local assiciates a global statement ID with a local statement ID for a specific connection
|
|
|
|
|
The implementation in ProxySQL is, simplified, the follow:
|
|
|
|
|
* when a client sends a MYSQL_COM_STMT_PREPARE, ProxySQL executes it to one of
|
|
|
|
|
the backend
|
|
|
|
|
* the backend returns a stmt_id. This stmt_id is NOT returned to the client. The
|
|
|
|
|
stmt_id returned from the backend is stored in MySQL_STMTs_local(), and
|
|
|
|
|
MySQL_STMTs_local() is responsible for mapping the connection's MYSQL_STMT
|
|
|
|
|
and a global_stmt_id
|
|
|
|
|
* the global_stmt_id is the stmt_id returned to the client
|
|
|
|
|
* the global_stmt_id is used to locate the relevant MySQL_STMT_Global_info() in
|
|
|
|
|
MySQL_STMT_Manager()
|
|
|
|
|
* MySQL_STMT_Global_info() stores all metadata associated with a PS
|
|
|
|
|
* MySQL_STMT_Manager() is responsible for storing all MySQL_STMT_Global_info()
|
|
|
|
|
in global structures accessible and shareble by all threads.
|
|
|
|
|
|
|
|
|
|
To summarie the most important classes:
|
|
|
|
|
* MySQL_STMT_Global_info() stores all metadata associated with a PS
|
|
|
|
|
* MySQL_STMT_Manager() stores all the MySQL_STMT_Global_info(), indexes using
|
|
|
|
|
a global_stmt_id that iis the stmt_id generated by ProxySQL and returned to
|
|
|
|
|
the client
|
|
|
|
|
* MySQL_STMTs_local() associate PS located in a backend connection to a
|
|
|
|
|
global_stmt_id
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// class MySQL_STMTs_local associates a global statement ID with a local statement ID for a specific connection
|
|
|
|
|
class MySQL_STMTs_local {
|
|
|
|
|
private:
|
|
|
|
|
unsigned int num_entries;
|
|
|
|
|
|