Rename query classifier functions consistently.

All public query classifier functions now have the prefix qc_.
This commit is contained in:
Johan Wikman
2016-01-11 10:58:39 +02:00
parent ec281849aa
commit 2f42246880
10 changed files with 58 additions and 59 deletions

View File

@ -108,7 +108,7 @@ bool ensure_query_is_parsed(GWBUF* query)
* *
* @return query type * @return query type
*/ */
skygw_query_type_t query_classifier_get_type(GWBUF* querybuf) skygw_query_type_t qc_get_type(GWBUF* querybuf)
{ {
MYSQL* mysql; MYSQL* mysql;
skygw_query_type_t qtype = QUERY_TYPE_UNKNOWN; skygw_query_type_t qtype = QUERY_TYPE_UNKNOWN;
@ -954,9 +954,7 @@ return_rc:
#if defined(NOT_USED) #if defined(NOT_USED)
char* char* qc_get_stmtname(GWBUF* buf)
skygw_query_classifier_get_stmtname(
GWBUF* buf)
{ {
MYSQL* mysql; MYSQL* mysql;
@ -1139,7 +1137,7 @@ retblock:
* @param querybuf Buffer to use. * @param querybuf Buffer to use.
* @return A pointer to the name if a table was created, otherwise NULL * @return A pointer to the name if a table was created, otherwise NULL
*/ */
char* skygw_get_created_table_name(GWBUF* querybuf) char* qc_get_created_table_name(GWBUF* querybuf)
{ {
if (querybuf == NULL) if (querybuf == NULL)
{ {
@ -1180,7 +1178,7 @@ char* skygw_get_created_table_name(GWBUF* querybuf)
* *
* @return true if the query is a real query, otherwise false * @return true if the query is a real query, otherwise false
*/ */
bool skygw_is_real_query(GWBUF* querybuf) bool qc_is_real_query(GWBUF* querybuf)
{ {
bool succp; bool succp;
LEX* lex; LEX* lex;
@ -1238,7 +1236,7 @@ retblock:
* @param querybuf Buffer to inspect * @param querybuf Buffer to inspect
* @return true if it contains the query otherwise false * @return true if it contains the query otherwise false
*/ */
bool is_drop_table_query(GWBUF* querybuf) bool qc_is_drop_table_query(GWBUF* querybuf)
{ {
bool answer = false; bool answer = false;
@ -1297,7 +1295,7 @@ inline void add_str(char** buf, int* buflen, int* bufsize, char* str)
* @param buf Buffer to parse * @param buf Buffer to parse
* @return Pointer to newly allocated string or NULL if nothing was found * @return Pointer to newly allocated string or NULL if nothing was found
*/ */
char* skygw_get_affected_fields(GWBUF* buf) char* qc_get_affected_fields(GWBUF* buf)
{ {
LEX* lex; LEX* lex;
int buffsz = 0, bufflen = 0; int buffsz = 0, bufflen = 0;
@ -1382,7 +1380,7 @@ char* skygw_get_affected_fields(GWBUF* buf)
return where; return where;
} }
bool skygw_query_has_clause(GWBUF* buf) bool qc_query_has_clause(GWBUF* buf)
{ {
bool clause = false; bool clause = false;
@ -1425,7 +1423,7 @@ bool skygw_query_has_clause(GWBUF* buf)
* Replaced literal types are STRING_ITEM,INT_ITEM,DECIMAL_ITEM,REAL_ITEM, * Replaced literal types are STRING_ITEM,INT_ITEM,DECIMAL_ITEM,REAL_ITEM,
* VARBIN_ITEM,NULL_ITEM * VARBIN_ITEM,NULL_ITEM
*/ */
char* skygw_get_canonical(GWBUF* querybuf) char* qc_get_canonical(GWBUF* querybuf)
{ {
parsing_info_t* pi; parsing_info_t* pi;
MYSQL* mysql; MYSQL* mysql;
@ -1643,7 +1641,7 @@ static void parsing_info_set_plain_str(void* ptr, char* str)
* *
* @return string representing the query type value * @return string representing the query type value
*/ */
char* skygw_get_qtype_str(skygw_query_type_t qtype) char* qc_get_qtype_str(skygw_query_type_t qtype)
{ {
int t1 = (int) qtype; int t1 = (int) qtype;
int t2 = 1; int t2 = 1;
@ -1693,7 +1691,7 @@ char* skygw_get_qtype_str(skygw_query_type_t qtype)
* @return A new array of strings containing the database names or NULL if no * @return A new array of strings containing the database names or NULL if no
* databases were found. * databases were found.
*/ */
char** skygw_get_database_names(GWBUF* querybuf, int* size) char** qc_get_database_names(GWBUF* querybuf, int* size)
{ {
LEX* lex; LEX* lex;
TABLE_LIST* tbl; TABLE_LIST* tbl;
@ -1753,7 +1751,7 @@ retblock:
return databases; return databases;
} }
skygw_query_op_t query_classifier_get_operation(GWBUF* querybuf) skygw_query_op_t qc_get_operation(GWBUF* querybuf)
{ {
skygw_query_op_t operation = QUERY_OP_UNDEFINED; skygw_query_op_t operation = QUERY_OP_UNDEFINED;

View File

@ -101,25 +101,26 @@ typedef struct parsing_info_st
* Create THD and use it for creating parse tree. Examine parse tree and * Create THD and use it for creating parse tree. Examine parse tree and
* classify the query. * classify the query.
*/ */
skygw_query_type_t query_classifier_get_type(GWBUF* querybuf); skygw_query_type_t qc_get_type(GWBUF* querybuf);
skygw_query_op_t query_classifier_get_operation(GWBUF* querybuf); skygw_query_op_t qc_get_operation(GWBUF* querybuf);
#if defined(NOT_USED) #if defined(NOT_USED)
char* skygw_query_classifier_get_stmtname(GWBUF* buf); char* qc_get_stmtname(GWBUF* buf);
#endif #endif
char* skygw_get_created_table_name(GWBUF* querybuf); char* qc_get_created_table_name(GWBUF* querybuf);
bool is_drop_table_query(GWBUF* querybuf); bool qc_is_drop_table_query(GWBUF* querybuf);
bool skygw_is_real_query(GWBUF* querybuf); bool qc_is_real_query(GWBUF* querybuf);
char** skygw_get_table_names(GWBUF* querybuf, int* tblsize, bool fullnames); char** qc_get_table_names(GWBUF* querybuf, int* tblsize, bool fullnames);
char* skygw_get_canonical(GWBUF* querybuf); char* qc_get_canonical(GWBUF* querybuf);
bool parse_query(GWBUF* querybuf); bool qc_query_has_clause(GWBUF* buf);
char* qc_get_qtype_str(skygw_query_type_t qtype);
char* qc_get_affected_fields(GWBUF* buf);
char** qc_get_database_names(GWBUF* querybuf, int* size);
// To be removed.
bool parse_query(GWBUF* querybuf);
bool query_is_parsed(GWBUF* buf); bool query_is_parsed(GWBUF* buf);
bool skygw_query_has_clause(GWBUF* buf);
char* skygw_get_qtype_str(skygw_query_type_t qtype);
char* skygw_get_affected_fields(GWBUF* buf);
char** skygw_get_database_names(GWBUF* querybuf, int* size);
EXTERN_C_BLOCK_END EXTERN_C_BLOCK_END

View File

@ -65,7 +65,7 @@ int main(int argc, char** argv)
*(qbuff->sbuf->data + 4) = 0x03; *(qbuff->sbuf->data + 4) = 0x03;
memcpy(qbuff->start + 5,readbuff,psize + 1); memcpy(qbuff->start + 5,readbuff,psize + 1);
parse_query(qbuff); parse_query(qbuff);
tok = skygw_get_canonical(qbuff); tok = qc_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok); fprintf(outfile,"%s\n",tok);
free(tok); free(tok);
gwbuf_free(qbuff); gwbuf_free(qbuff);

View File

@ -108,7 +108,7 @@ int main(int argc, char** argv)
memmove(strbuff,tok + 1, strsz - qlen); memmove(strbuff,tok + 1, strsz - qlen);
strsz -= qlen; strsz -= qlen;
memset(strbuff + strsz,0,buffsz - strsz); memset(strbuff + strsz,0,buffsz - strsz);
skygw_query_type_t type = query_classifier_get_type(buff); skygw_query_type_t type = qc_get_type(buff);
char qtypestr[64]; char qtypestr[64];
char expbuff[256]; char expbuff[256];
int expos = 0; int expos = 0;

View File

@ -1610,8 +1610,8 @@ bool rule_matches(FW_INSTANCE* my_instance,
if (is_sql) if (is_sql)
{ {
optype = query_classifier_get_operation(queue); optype = qc_get_operation(queue);
is_real = skygw_is_real_query(queue); is_real = qc_is_real_query(queue);
} }
if (rulelist->rule->on_queries == QUERY_OP_UNDEFINED || rulelist->rule->on_queries & optype) if (rulelist->rule->on_queries == QUERY_OP_UNDEFINED || rulelist->rule->on_queries & optype)
@ -1660,7 +1660,7 @@ bool rule_matches(FW_INSTANCE* my_instance,
case RT_COLUMN: case RT_COLUMN:
if (is_sql && is_real) if (is_sql && is_real)
{ {
where = skygw_get_affected_fields(queue); where = qc_get_affected_fields(queue);
if (where != NULL) if (where != NULL)
{ {
char* saveptr; char* saveptr;
@ -1700,7 +1700,7 @@ bool rule_matches(FW_INSTANCE* my_instance,
if (is_sql && is_real) if (is_sql && is_real)
{ {
char * strptr; char * strptr;
where = skygw_get_affected_fields(queue); where = qc_get_affected_fields(queue);
if (where != NULL) if (where != NULL)
{ {
@ -1809,7 +1809,7 @@ bool rule_matches(FW_INSTANCE* my_instance,
case RT_CLAUSE: case RT_CLAUSE:
if (is_sql && is_real && if (is_sql && is_real &&
!skygw_query_has_clause(queue)) !qc_query_has_clause(queue))
{ {
matches = true; matches = true;
msg = strdup("Required WHERE/HAVING clause is missing."); msg = strdup("Required WHERE/HAVING clause is missing.");

View File

@ -1129,7 +1129,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
if (!my_instance->log_all) if (!my_instance->log_all)
{ {
if (!skygw_is_real_query(queue)) if (!qc_is_real_query(queue))
{ {
goto send_downstream; goto send_downstream;
} }
@ -1200,7 +1200,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
if (my_instance->trgtype & TRG_SCHEMA && my_instance->shm_trg) if (my_instance->trgtype & TRG_SCHEMA && my_instance->shm_trg)
{ {
int tbsz = 0, z; int tbsz = 0, z;
char** tblnames = skygw_get_table_names(queue, &tbsz, true); char** tblnames = qc_get_table_names(queue, &tbsz, true);
char* tmp; char* tmp;
bool all_remotes = true; bool all_remotes = true;
@ -1267,7 +1267,7 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
if (my_instance->trgtype & TRG_OBJECT && my_instance->obj_trg) if (my_instance->trgtype & TRG_OBJECT && my_instance->obj_trg)
{ {
sesstbls = skygw_get_table_names(queue, &dbcount, false); sesstbls = qc_get_table_names(queue, &dbcount, false);
for (j = 0; j < dbcount; j++) for (j = 0; j < dbcount; j++)
{ {
@ -1384,7 +1384,7 @@ validate_triggers:
{ {
/**Try to convert to a canonical form and use the plain query if unsuccessful*/ /**Try to convert to a canonical form and use the plain query if unsuccessful*/
if ((canon_q = skygw_get_canonical(queue)) == NULL) if ((canon_q = qc_get_canonical(queue)) == NULL)
{ {
MXS_ERROR("Cannot form canonical query."); MXS_ERROR("Cannot form canonical query.");
} }

View File

@ -1607,9 +1607,9 @@ void check_drop_tmp_table(
dbname = (char*)data->db; dbname = (char*)data->db;
if (is_drop_table_query(querybuf)) if (qc_is_drop_table_query(querybuf))
{ {
tbl = skygw_get_table_names(querybuf,&tsize,false); tbl = qc_get_table_names(querybuf,&tsize,false);
if(tbl != NULL){ if(tbl != NULL){
for(i = 0; i<tsize; i++) for(i = 0; i<tsize; i++)
{ {
@ -1703,7 +1703,7 @@ static skygw_query_type_t is_read_tmp_table(
QUERY_IS_TYPE(qtype, QUERY_TYPE_SYSVAR_READ) || QUERY_IS_TYPE(qtype, QUERY_TYPE_SYSVAR_READ) ||
QUERY_IS_TYPE(qtype, QUERY_TYPE_GSYSVAR_READ)) QUERY_IS_TYPE(qtype, QUERY_TYPE_GSYSVAR_READ))
{ {
tbl = skygw_get_table_names(querybuf,&tsize,false); tbl = qc_get_table_names(querybuf,&tsize,false);
if (tbl != NULL && tsize > 0) if (tbl != NULL && tsize > 0)
{ {
@ -1808,7 +1808,7 @@ static void check_create_tmp_table(
bool is_temp = true; bool is_temp = true;
char* tblname = NULL; char* tblname = NULL;
tblname = skygw_get_created_table_name(querybuf); tblname = qc_get_created_table_name(querybuf);
if (tblname && strlen(tblname) > 0) if (tblname && strlen(tblname) > 0)
{ {
@ -2145,11 +2145,11 @@ static bool route_single_stmt(
break; break;
case MYSQL_COM_QUERY: case MYSQL_COM_QUERY:
qtype = query_classifier_get_type(querybuf); qtype = qc_get_type(querybuf);
break; break;
case MYSQL_COM_STMT_PREPARE: case MYSQL_COM_STMT_PREPARE:
qtype = query_classifier_get_type(querybuf); qtype = qc_get_type(querybuf);
qtype |= QUERY_TYPE_PREPARE_STMT; qtype |= QUERY_TYPE_PREPARE_STMT;
break; break;
@ -2195,7 +2195,7 @@ static bool route_single_stmt(
*/ */
if (!rses->rses_load_active) if (!rses->rses_load_active)
{ {
skygw_query_op_t queryop = query_classifier_get_operation(querybuf); skygw_query_op_t queryop = qc_get_operation(querybuf);
if (queryop == QUERY_OP_LOAD) if (queryop == QUERY_OP_LOAD)
{ {
rses->rses_load_active = true; rses->rses_load_active = true;
@ -2255,7 +2255,7 @@ static bool route_single_stmt(
MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start) - 1); MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start) - 1);
char* data = (char*) &packet[5]; char* data = (char*) &packet[5];
char* contentstr = strndup(data, MIN(len, RWSPLIT_TRACE_MSG_LEN)); char* contentstr = strndup(data, MIN(len, RWSPLIT_TRACE_MSG_LEN));
char* qtypestr = skygw_get_qtype_str(qtype); char* qtypestr = qc_get_qtype_str(qtype);
MXS_INFO("> Autocommit: %s, trx is %s, cmd: %s, type: %s, " MXS_INFO("> Autocommit: %s, trx is %s, cmd: %s, type: %s, "
"stmt: %s%s %s", "stmt: %s%s %s",
@ -2308,7 +2308,7 @@ static bool route_single_stmt(
backend_ref_t* bref = rses->rses_backend_ref; backend_ref_t* bref = rses->rses_backend_ref;
char* query_str = modutil_get_query(querybuf); char* query_str = modutil_get_query(querybuf);
char* qtype_str = skygw_get_qtype_str(qtype); char* qtype_str = qc_get_qtype_str(qtype);
MXS_ERROR("Can't route %s:%s:\"%s\". SELECT with " MXS_ERROR("Can't route %s:%s:\"%s\". SELECT with "
"session data modification is not supported " "session data modification is not supported "

View File

@ -522,7 +522,7 @@ char* get_shard_target_name(ROUTER_INSTANCE* router, ROUTER_CLIENT_SES* client,
char* rval = NULL,*query, *tmp = NULL; char* rval = NULL,*query, *tmp = NULL;
bool has_dbs = false; /**If the query targets any database other than the current one*/ bool has_dbs = false; /**If the query targets any database other than the current one*/
dbnms = skygw_get_database_names(buffer,&sz); dbnms = qc_get_database_names(buffer,&sz);
HASHTABLE* ht = client->shardmap->hash; HASHTABLE* ht = client->shardmap->hash;
@ -1537,9 +1537,9 @@ ROUTER* instance,
rses_prop_tmp = router_cli_ses->rses_properties[RSES_PROP_TYPE_TMPTABLES]; rses_prop_tmp = router_cli_ses->rses_properties[RSES_PROP_TYPE_TMPTABLES];
dbname = router_cli_ses->current_db; dbname = router_cli_ses->current_db;
if (is_drop_table_query(querybuf)) if (qc_is_drop_table_query(querybuf))
{ {
tbl = skygw_get_table_names(querybuf,&tsize,false); tbl = qc_get_table_names(querybuf,&tsize,false);
if(tbl != NULL){ if(tbl != NULL){
for(i = 0; i<tsize; i++) for(i = 0; i<tsize; i++)
{ {
@ -1600,7 +1600,7 @@ ROUTER* instance,
QUERY_IS_TYPE(qtype, QUERY_TYPE_SYSVAR_READ) || QUERY_IS_TYPE(qtype, QUERY_TYPE_SYSVAR_READ) ||
QUERY_IS_TYPE(qtype, QUERY_TYPE_GSYSVAR_READ)) QUERY_IS_TYPE(qtype, QUERY_TYPE_GSYSVAR_READ))
{ {
tbl = skygw_get_table_names(querybuf,&tsize,false); tbl = qc_get_table_names(querybuf,&tsize,false);
if (tbl != NULL && tsize > 0) if (tbl != NULL && tsize > 0)
{ {
@ -1677,7 +1677,7 @@ void check_create_tmp_table(
bool is_temp = true; bool is_temp = true;
char* tblname = NULL; char* tblname = NULL;
tblname = skygw_get_created_table_name(querybuf); tblname = qc_get_created_table_name(querybuf);
if (tblname && strlen(tblname) > 0) if (tblname && strlen(tblname) > 0)
{ {
@ -2014,11 +2014,11 @@ static int routeQuery(
break; break;
case MYSQL_COM_QUERY: case MYSQL_COM_QUERY:
qtype = query_classifier_get_type(querybuf); qtype = qc_get_type(querybuf);
break; break;
case MYSQL_COM_STMT_PREPARE: case MYSQL_COM_STMT_PREPARE:
qtype = query_classifier_get_type(querybuf); qtype = qc_get_type(querybuf);
qtype |= QUERY_TYPE_PREPARE_STMT; qtype |= QUERY_TYPE_PREPARE_STMT;
break; break;
@ -2048,7 +2048,7 @@ static int routeQuery(
MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start)-1); MYSQL_GET_PACKET_LEN((unsigned char *)querybuf->start)-1);
char* data = (char*)&packet[5]; char* data = (char*)&packet[5];
char* contentstr = strndup(data, len); char* contentstr = strndup(data, len);
char* qtypestr = skygw_get_qtype_str(qtype); char* qtypestr = qc_get_qtype_str(qtype);
MXS_INFO("> Cmd: %s, type: %s, " MXS_INFO("> Cmd: %s, type: %s, "
"stmt: %s%s %s", "stmt: %s%s %s",
@ -2066,7 +2066,7 @@ static int routeQuery(
* all of them. * all of them.
*/ */
skygw_query_op_t op = query_classifier_get_operation(querybuf); skygw_query_op_t op = qc_get_operation(querybuf);
if (packet_type == MYSQL_COM_INIT_DB || if (packet_type == MYSQL_COM_INIT_DB ||
op == QUERY_OP_CHANGE_DB) op == QUERY_OP_CHANGE_DB)

View File

@ -35,7 +35,7 @@ bool extract_database(GWBUF* buf, char* str)
plen = gw_mysql_get_byte3(packet) - 1; plen = gw_mysql_get_byte3(packet) - 1;
/** Copy database name from MySQL packet to session */ /** Copy database name from MySQL packet to session */
if(query_classifier_get_operation(buf) == QUERY_OP_CHANGE_DB) if(qc_get_operation(buf) == QUERY_OP_CHANGE_DB)
{ {
query = modutil_get_SQL(buf); query = modutil_get_SQL(buf);
tok = strtok_r(query," ;",&saved); tok = strtok_r(query," ;",&saved);

View File

@ -447,7 +447,7 @@ get_shard_target_name(ROUTER_INSTANCE* router, ROUTER_CLIENT_SES* client, GWBUF*
char *query = NULL,*tmp = NULL; char *query = NULL,*tmp = NULL;
bool has_dbs = false; /**If the query targets any database other than the current one*/ bool has_dbs = false; /**If the query targets any database other than the current one*/
dbnms = skygw_get_database_names(buffer, &sz); dbnms = qc_get_database_names(buffer, &sz);
if(sz > 0) if(sz > 0)
{ {
@ -1607,11 +1607,11 @@ routeQuery(ROUTER* instance,
break; break;
case MYSQL_COM_QUERY: case MYSQL_COM_QUERY:
qtype = query_classifier_get_type(querybuf); qtype = qc_get_type(querybuf);
break; break;
case MYSQL_COM_STMT_PREPARE: case MYSQL_COM_STMT_PREPARE:
qtype = query_classifier_get_type(querybuf); qtype = qc_get_type(querybuf);
qtype |= QUERY_TYPE_PREPARE_STMT; qtype |= QUERY_TYPE_PREPARE_STMT;
break; break;