MXS-1625 Move check_create_tmp_table() to QueryClassifier

This commit is contained in:
Johan Wikman
2018-04-09 13:54:13 +03:00
parent c8673bc0b3
commit 505d6b5889
3 changed files with 39 additions and 33 deletions

View File

@ -203,6 +203,8 @@ public:
static uint32_t determine_query_type(GWBUF *querybuf, int command);
void check_create_tmp_table(GWBUF *querybuf, uint32_t type);
private:
class PSManager;
typedef std::shared_ptr<PSManager> SPSManager;

View File

@ -571,5 +571,41 @@ uint32_t QueryClassifier::determine_query_type(GWBUF *querybuf, int command)
return type;
}
namespace
{
// Copied from mysql_common.c
// TODO: The current database should somehow be available in a generic fashion.
const char* qc_mysql_get_current_db(MXS_SESSION* session)
{
MYSQL_session* data = (MYSQL_session*)session->client_dcb->data;
return data->db;
}
}
void QueryClassifier::check_create_tmp_table(GWBUF *querybuf, uint32_t type)
{
if (qc_query_is_type(type, QUERY_TYPE_CREATE_TMP_TABLE))
{
set_have_tmp_tables(true);
char* tblname = qc_get_created_table_name(querybuf);
std::string table;
if (tblname && *tblname && strchr(tblname, '.') == NULL)
{
const char* db = qc_mysql_get_current_db(session());
table += db;
table += ".";
table += tblname;
}
/** Add the table to the set of temporary tables */
add_tmp_table(table);
MXS_FREE(tblname);
}
}
}

View File

@ -23,38 +23,6 @@ using mxs::QueryClassifier;
namespace
{
/**
* If query is of type QUERY_TYPE_CREATE_TMP_TABLE then find out
* the database and table name, create a hashvalue and
* add it to the router client session's property. If property
* doesn't exist then create it first.
* @param qc The query classifier.
* @param querybuf GWBUF containing the query
* @param type The type of the query resolved so far
*/
void check_create_tmp_table(QueryClassifier& qc, GWBUF *querybuf, uint32_t type)
{
if (qc_query_is_type(type, QUERY_TYPE_CREATE_TMP_TABLE))
{
qc.set_have_tmp_tables(true);
char* tblname = qc_get_created_table_name(querybuf);
std::string table;
if (tblname && *tblname && strchr(tblname, '.') == NULL)
{
const char* db = mxs_mysql_get_current_db(qc.session());
table += db;
table += ".";
table += tblname;
}
/** Add the table to the set of temporary tables */
qc.add_tmp_table(table);
MXS_FREE(tblname);
}
}
/**
* Find callback for foreach_table
*/
@ -287,7 +255,7 @@ handle_multi_temp_and_load(QueryClassifier& qc,
}
}
check_create_tmp_table(qc, querybuf, *qtype);
qc.check_create_tmp_table(querybuf, *qtype);
/**
* Check if this is a LOAD DATA LOCAL INFILE query. If so, send all queries