Optimize connection pool to find matching username

Try to get from connection pool and connections cache, a connection with the same schemaname
pull/1867/head
René Cannaò 7 years ago
parent 8dd1bf0967
commit 11924ca129

@ -2341,13 +2341,14 @@ MySQL_Connection * MySrvConnList::get_random_MyConn(MySQL_Session *sess, bool ff
i=fastrand()%l;
}
if (sess && sess->client_myds && sess->client_myds->myconn && sess->client_myds->myconn->userinfo) {
// try to match schemaname
// try to match schemaname AND username
char *schema = sess->client_myds->myconn->userinfo->schemaname;
char *username = sess->client_myds->myconn->userinfo->username;
bool conn_found = false;
unsigned int k;
for (k = i; conn_found == false && k < l; k++) {
conn = (MySQL_Connection *)conns->index(k);
if (strcmp(conn->userinfo->schemaname,schema)==0) {
if (strcmp(conn->userinfo->schemaname,schema)==0 && strcmp(conn->userinfo->username,username)==0) {
conn_found = true;
i = k;
}
@ -2355,7 +2356,7 @@ MySQL_Connection * MySrvConnList::get_random_MyConn(MySQL_Session *sess, bool ff
if (conn_found == false ) {
for (k = 0; conn_found == false && k < i; k++) {
conn = (MySQL_Connection *)conns->index(k);
if (strcmp(conn->userinfo->schemaname,schema)==0) {
if (strcmp(conn->userinfo->schemaname,schema)==0 && strcmp(conn->userinfo->username,username)==0) {
conn_found = true;
i = k;
}

@ -5097,7 +5097,8 @@ MySQL_Connection * MySQL_Thread::get_MyConn_local(unsigned int _hid, MySQL_Sessi
//npc++;
if (sess && sess->client_myds && sess->client_myds->myconn && sess->client_myds->myconn->userinfo) {
char *schema = sess->client_myds->myconn->userinfo->schemaname;
if (strcmp(c->userinfo->schemaname,schema)==0) {
char *username = sess->client_myds->myconn->userinfo->username;
if (strcmp(c->userinfo->schemaname,schema)==0 && strcmp(c->userinfo->username,username)==0) {
c=(MySQL_Connection *)cached_connections->remove_index_fast(i);
return c;
}
@ -5125,7 +5126,8 @@ MySQL_Connection * MySQL_Thread::get_MyConn_local(unsigned int _hid, MySQL_Sessi
npc++;
if (sess && sess->client_myds && sess->client_myds->myconn && sess->client_myds->myconn->userinfo) {
char *schema = sess->client_myds->myconn->userinfo->schemaname;
if (strcmp(c->userinfo->schemaname,schema)==0) {
char *username = sess->client_myds->myconn->userinfo->username;
if (strcmp(c->userinfo->schemaname,schema)==0 && strcmp(c->userinfo->username,username)==0) {
c=(MySQL_Connection *)cached_connections->remove_index_fast(i);
return c;
}

Loading…
Cancel
Save