MXS-1625 Move check_create_tmp_table() to QueryClassifier
This commit is contained in:
@ -203,6 +203,8 @@ public:
|
|||||||
|
|
||||||
static uint32_t determine_query_type(GWBUF *querybuf, int command);
|
static uint32_t determine_query_type(GWBUF *querybuf, int command);
|
||||||
|
|
||||||
|
void check_create_tmp_table(GWBUF *querybuf, uint32_t type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PSManager;
|
class PSManager;
|
||||||
typedef std::shared_ptr<PSManager> SPSManager;
|
typedef std::shared_ptr<PSManager> SPSManager;
|
||||||
|
|||||||
@ -571,5 +571,41 @@ uint32_t QueryClassifier::determine_query_type(GWBUF *querybuf, int command)
|
|||||||
return type;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,38 +23,6 @@ using mxs::QueryClassifier;
|
|||||||
namespace
|
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
|
* 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
|
* Check if this is a LOAD DATA LOCAL INFILE query. If so, send all queries
|
||||||
|
|||||||
Reference in New Issue
Block a user