diff --git a/include/maxscale/query_classifier.h b/include/maxscale/query_classifier.h index 9b0481be0..427e087a8 100644 --- a/include/maxscale/query_classifier.h +++ b/include/maxscale/query_classifier.h @@ -204,7 +204,7 @@ typedef struct query_classifier * @return QC_RESULT_OK, if the parsing was not aborted due to resource * exhaustion or equivalent. */ - int32_t (*qc_get_type)(GWBUF* stmt, uint32_t* type); + int32_t (*qc_get_type_mask)(GWBUF* stmt, uint32_t* type); /** * Reports the operation of the statement. @@ -448,7 +448,7 @@ void qc_thread_end(void); * to what extent the statement could be parsed. * * There is no need to call this function explicitly before calling any of - * the other functions; e.g. qc_get_type(). When some particular property of + * the other functions; e.g. qc_get_type_mask(). When some particular property of * a statement is asked for, the statement will be parsed if it has not been * parsed yet. Also, if the statement in the provided buffer has been parsed * already then this function will only return the result of that parsing; @@ -621,7 +621,7 @@ char** qc_get_table_names(GWBUF* stmt, int* size, bool fullnames); * * @see qc_query_is_type */ -uint32_t qc_get_type(GWBUF* stmt); +uint32_t qc_get_type_mask(GWBUF* stmt); /** * Returns whether the statement is a DROP TABLE statement. diff --git a/query_classifier/qc_dummy/qc_dummy.cc b/query_classifier/qc_dummy/qc_dummy.cc index 3d2218ed4..7dffa48d9 100644 --- a/query_classifier/qc_dummy/qc_dummy.cc +++ b/query_classifier/qc_dummy/qc_dummy.cc @@ -21,7 +21,7 @@ int32_t qc_dummy_parse(GWBUF* querybuf, int32_t* pResult) return QC_RESULT_OK; } -int32_t qc_dummy_get_type(GWBUF* querybuf, uint32_t* pType_mask) +int32_t qc_dummy_get_type_mask(GWBUF* querybuf, uint32_t* pType_mask) { *pType_mask = QUERY_TYPE_UNKNOWN; return QC_RESULT_OK; @@ -126,7 +126,7 @@ extern "C" qc_dummy_thread_init, qc_dummy_thread_end, qc_dummy_parse, - qc_dummy_get_type, + qc_dummy_get_type_mask, qc_dummy_get_operation, qc_dummy_get_created_table_name, qc_dummy_is_drop_table_query, diff --git a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc index bdc610885..595ebbe74 100644 --- a/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc +++ b/query_classifier/qc_mysqlembedded/qc_mysqlembedded.cc @@ -158,7 +158,7 @@ int32_t qc_mysql_parse(GWBUF* querybuf, int32_t* result) return QC_RESULT_OK; } -int32_t qc_mysql_get_type(GWBUF* querybuf, uint32_t* type_mask) +int32_t qc_mysql_get_type_mask(GWBUF* querybuf, uint32_t* type_mask) { *type_mask = QUERY_TYPE_UNKNOWN; MYSQL* mysql; @@ -2731,7 +2731,7 @@ extern "C" qc_mysql_thread_init, qc_mysql_thread_end, qc_mysql_parse, - qc_mysql_get_type, + qc_mysql_get_type_mask, qc_mysql_get_operation, qc_mysql_get_created_table_name, qc_mysql_is_drop_table_query, diff --git a/query_classifier/qc_sqlite/qc_sqlite.c b/query_classifier/qc_sqlite/qc_sqlite.c index d807af08a..c84fa759f 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.c +++ b/query_classifier/qc_sqlite/qc_sqlite.c @@ -58,7 +58,7 @@ typedef struct qc_sqlite_info const char* query; // The query passed to sqlite. size_t query_len; // The length of the query. - uint32_t types; // The types of the query. + uint32_t type_mask; // The type mask of the query. qc_query_op_t operation; // The operation in question. bool has_clause; // Has WHERE or HAVING. char** table_names; // Array of table names used in the query. @@ -365,7 +365,7 @@ static QC_SQLITE_INFO* info_init(QC_SQLITE_INFO* info) info->status = QC_QUERY_INVALID; - info->types = QUERY_TYPE_UNKNOWN; + info->type_mask = QUERY_TYPE_UNKNOWN; info->operation = QUERY_OP_UNDEFINED; info->has_clause = false; info->table_names = NULL; @@ -529,7 +529,7 @@ static bool parse_query(GWBUF* query) if (command == MYSQL_COM_STMT_PREPARE) { - info->types |= QUERY_TYPE_PREPARE_STMT; + info->type_mask |= QUERY_TYPE_PREPARE_STMT; } // TODO: Add return value to gwbuf_add_buffer_object. @@ -964,18 +964,18 @@ static void update_field_infos(QC_SQLITE_INFO* info, { if ((prev_token == TK_EQ) && (pos == QC_TOKEN_LEFT)) { - info->types |= QUERY_TYPE_GSYSVAR_WRITE; + info->type_mask |= QUERY_TYPE_GSYSVAR_WRITE; } else { if ((strcasecmp(&zToken[2], "identity") == 0) || (strcasecmp(&zToken[2], "last_insert_id") == 0)) { - info->types |= QUERY_TYPE_MASTER_READ; + info->type_mask |= QUERY_TYPE_MASTER_READ; } else { - info->types |= QUERY_TYPE_SYSVAR_READ; + info->type_mask |= QUERY_TYPE_SYSVAR_READ; } } } @@ -983,11 +983,11 @@ static void update_field_infos(QC_SQLITE_INFO* info, { if ((prev_token == TK_EQ) && (pos == QC_TOKEN_LEFT)) { - info->types |= QUERY_TYPE_USERVAR_WRITE; + info->type_mask |= QUERY_TYPE_USERVAR_WRITE; } else { - info->types |= QUERY_TYPE_USERVAR_READ; + info->type_mask |= QUERY_TYPE_USERVAR_READ; } } } @@ -1047,11 +1047,11 @@ static void update_field_infos(QC_SQLITE_INFO* info, { if (strcasecmp(zToken, "last_insert_id") == 0) { - info->types |= (QUERY_TYPE_READ | QUERY_TYPE_MASTER_READ); + info->type_mask |= (QUERY_TYPE_READ | QUERY_TYPE_MASTER_READ); } else if (!is_builtin_readonly_function(zToken)) { - info->types |= QUERY_TYPE_WRITE; + info->type_mask |= QUERY_TYPE_WRITE; } // We exclude "row", because we cannot detect all rows the same @@ -1284,7 +1284,7 @@ void mxs_sqlite3AlterFinishAddColumn(Parse* pParse, Token* pToken) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_ALTER; } @@ -1308,7 +1308,7 @@ void mxs_sqlite3Analyze(Parse* pParse, SrcList* pSrcList) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); update_names_from_srclist(info, pSrcList); @@ -1323,7 +1323,7 @@ void mxs_sqlite3BeginTransaction(Parse* pParse, int type) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_BEGIN_TRX | type; + info->type_mask = QUERY_TYPE_BEGIN_TRX | type; } void mxs_sqlite3BeginTrigger(Parse *pParse, /* The parse context of the CREATE TRIGGER statement */ @@ -1343,7 +1343,7 @@ void mxs_sqlite3BeginTrigger(Parse *pParse, /* The parse context of the CRE ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); if (pTableName) { @@ -1371,7 +1371,7 @@ void mxs_sqlite3CommitTransaction(Parse* pParse) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_COMMIT; + info->type_mask = QUERY_TYPE_COMMIT; } void mxs_sqlite3CreateIndex(Parse *pParse, /* All information about this parse */ @@ -1391,7 +1391,7 @@ void mxs_sqlite3CreateIndex(Parse *pParse, /* All information about this par ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_CREATE; if (pTblName) @@ -1422,7 +1422,7 @@ void mxs_sqlite3CreateView(Parse *pParse, /* The parsing context */ ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_CREATE; const Token* pName = pName2->z ? pName2 : pName1; @@ -1462,7 +1462,7 @@ void mxs_sqlite3DeleteFrom(Parse* pParse, SrcList* pTabList, Expr* pWhere, SrcLi ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_DELETE; info->has_clause = pWhere ? true : false; @@ -1531,7 +1531,7 @@ void mxs_sqlite3DropIndex(Parse* pParse, SrcList* pName, SrcList* pTable, int bi ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_DROP; update_names_from_srclist(info, pTable); @@ -1548,10 +1548,10 @@ void mxs_sqlite3DropTable(Parse *pParse, SrcList *pName, int isView, int noErr, ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; if (!isTemp) { - info->types |= QUERY_TYPE_COMMIT; + info->type_mask |= QUERY_TYPE_COMMIT; } info->operation = QUERY_OP_DROP; if (!isView) @@ -1615,7 +1615,7 @@ void mxs_sqlite3Insert(Parse* pParse, ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_INSERT; ss_dassert(pTabList); ss_dassert(pTabList->nSrc >= 1); @@ -1661,7 +1661,7 @@ void mxs_sqlite3RollbackTransaction(Parse* pParse) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_ROLLBACK; + info->type_mask = QUERY_TYPE_ROLLBACK; } int mxs_sqlite3Select(Parse* pParse, Select* p, SelectDest* pDest) @@ -1705,15 +1705,15 @@ void mxs_sqlite3StartTable(Parse *pParse, /* Parser context */ { info->status = QC_QUERY_PARSED; info->operation = QUERY_OP_CREATE; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; if (isTemp) { - info->types |= QUERY_TYPE_CREATE_TMP_TABLE; + info->type_mask |= QUERY_TYPE_CREATE_TMP_TABLE; } else { - info->types |= QUERY_TYPE_COMMIT; + info->type_mask |= QUERY_TYPE_COMMIT; } const Token* pName = pName2->z ? pName2 : pName1; @@ -1753,7 +1753,7 @@ void mxs_sqlite3Update(Parse* pParse, SrcList* pTabList, ExprList* pChanges, Exp ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_UPDATE; update_names_from_srclist(info, pTabList); info->has_clause = (pWhere ? true : false); @@ -1787,13 +1787,13 @@ void maxscaleCollectInfoFromSelect(Parse* pParse, Select* pSelect, int sub_selec { // If there's a single variable, then it's a write. // mysql embedded considers it a system var write. - info->types = QUERY_TYPE_GSYSVAR_WRITE; + info->type_mask = QUERY_TYPE_GSYSVAR_WRITE; // Also INTO {OUTFILE|DUMPFILE} will be typed as QUERY_TYPE_GSYSVAR_WRITE. } else { - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; } uint32_t usage = sub_select ? QC_USED_IN_SUBSELECT : QC_USED_IN_SELECT; @@ -1812,7 +1812,7 @@ void maxscaleAlterTable(Parse *pParse, /* Parser context. */ ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_ALTER; switch (command) @@ -1844,7 +1844,7 @@ void maxscaleCall(Parse* pParse, SrcList* pName) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; exposed_sqlite3SrcListDelete(pParse->db, pName); } @@ -1857,7 +1857,7 @@ void maxscaleCheckTable(Parse* pParse, SrcList* pTables) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); update_names_from_srclist(info, pTables); @@ -1874,7 +1874,7 @@ void maxscaleComment() if (info->status == QC_QUERY_INVALID) { info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; } } @@ -1886,7 +1886,7 @@ void maxscaleDeallocate(Parse* pParse, Token* pName) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->prepare_name = MXS_MALLOC(pName->n + 1); if (info->prepare_name) @@ -1904,7 +1904,7 @@ void maxscaleDo(Parse* pParse, ExprList* pEList) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_READ | QUERY_TYPE_WRITE); + info->type_mask = (QUERY_TYPE_READ | QUERY_TYPE_WRITE); exposed_sqlite3ExprListDelete(pParse->db, pEList); } @@ -1917,7 +1917,7 @@ void maxscaleDrop(Parse* pParse, MxsDrop* pDrop) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_DROP; } @@ -1929,7 +1929,7 @@ void maxscaleExecute(Parse* pParse, Token* pName) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->prepare_name = MXS_MALLOC(pName->n + 1); if (info->prepare_name) @@ -1947,7 +1947,7 @@ void maxscaleExplain(Parse* pParse, SrcList* pName) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; update_names(info, pName->a[0].zDatabase, pName->a[0].zName); uint32_t u = QC_USED_IN_SELECT; update_field_info(info, "information_schema", "COLUMNS", "COLUMN_DEFAULT", u, NULL); @@ -1968,7 +1968,7 @@ void maxscaleFlush(Parse* pParse, Token* pWhat) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); } void maxscaleHandler(Parse* pParse, mxs_handler_t type, SrcList* pFullName, Token* pName) @@ -1984,7 +1984,7 @@ void maxscaleHandler(Parse* pParse, mxs_handler_t type, SrcList* pFullName, Toke { case MXS_HANDLER_OPEN: { - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; ss_dassert(pFullName->nSrc == 1); const struct SrcList_item* pItem = &pFullName->a[0]; @@ -1995,7 +1995,7 @@ void maxscaleHandler(Parse* pParse, mxs_handler_t type, SrcList* pFullName, Toke case MXS_HANDLER_CLOSE: { - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; char zName[pName->n + 1]; strncpy(zName, pName->z, pName->n); @@ -2020,7 +2020,7 @@ void maxscaleLoadData(Parse* pParse, SrcList* pFullName) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_LOAD; if (pFullName) @@ -2039,7 +2039,7 @@ void maxscaleLock(Parse* pParse, mxs_lock_t type, SrcList* pTables) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; if (pTables) { @@ -2073,51 +2073,51 @@ void maxscaleKeyword(int token) { case TK_ALTER: info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_ALTER; break; case TK_CALL: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; break; case TK_CREATE: info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_CREATE; break; case TK_DELETE: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_DELETE; break; case TK_DESC: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; break; case TK_DROP: info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_DROP; break; case TK_EXECUTE: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; break; case TK_EXPLAIN: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; break; case TK_GRANT: info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_GRANT; break; @@ -2127,68 +2127,68 @@ void maxscaleKeyword(int token) case TK_INSERT: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_INSERT; break; case TK_LOCK: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; break; case TK_PREPARE: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_PREPARE_NAMED_STMT; + info->type_mask = QUERY_TYPE_PREPARE_NAMED_STMT; break; case TK_REPLACE: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_INSERT; break; case TK_REVOKE: info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_REVOKE; break; case TK_SELECT: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; info->operation = QUERY_OP_SELECT; break; case TK_SET: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_GSYSVAR_WRITE; + info->type_mask = QUERY_TYPE_GSYSVAR_WRITE; break; case TK_SHOW: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; break; case TK_START: // Will produce the right info for START SLAVE. info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; break; case TK_UNLOCK: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; break; case TK_UPDATE: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_UPDATE; break; case TK_TRUNCATE: info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); break; default: @@ -2205,7 +2205,7 @@ void maxscaleKeyword(int token) if (info->keyword_2 == TK_TABLE) { info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); } break; @@ -2213,7 +2213,7 @@ void maxscaleKeyword(int token) if (info->keyword_2 == TK_PREPARE) { info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_SESSION_WRITE; + info->type_mask = QUERY_TYPE_SESSION_WRITE; } break; @@ -2221,7 +2221,7 @@ void maxscaleKeyword(int token) if (info->keyword_2 == TK_DATA) { info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; info->operation = QUERY_OP_LOAD; } break; @@ -2230,7 +2230,7 @@ void maxscaleKeyword(int token) if (info->keyword_2 == TK_TABLE) { info->status = QC_QUERY_TOKENIZED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); } break; @@ -2239,7 +2239,7 @@ void maxscaleKeyword(int token) { case TK_TRANSACTION: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_BEGIN_TRX; + info->type_mask = QUERY_TYPE_BEGIN_TRX; break; default: @@ -2252,12 +2252,12 @@ void maxscaleKeyword(int token) { case TK_DATABASES_KW: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_SHOW_DATABASES; + info->type_mask = QUERY_TYPE_SHOW_DATABASES; break; case TK_TABLES: info->status = QC_QUERY_TOKENIZED; - info->types = QUERY_TYPE_SHOW_TABLES; + info->type_mask = QUERY_TYPE_SHOW_TABLES; break; default: @@ -2275,7 +2275,7 @@ void maxscaleRenameTable(Parse* pParse, SrcList* pTables) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT; + info->type_mask = QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT; for (int i = 0; i < pTables->nSrc; ++i) { @@ -2299,7 +2299,7 @@ void maxscalePrepare(Parse* pParse, Token* pName, Token* pStmt) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_PREPARE_NAMED_STMT; + info->type_mask = QUERY_TYPE_PREPARE_NAMED_STMT; info->prepare_name = MXS_MALLOC(pName->n + 1); if (info->prepare_name) @@ -2338,7 +2338,7 @@ void maxscalePrivileges(Parse* pParse, int kind) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); switch (kind) { @@ -2379,19 +2379,19 @@ void maxscaleSet(Parse* pParse, int scope, mxs_set_t kind, ExprList* pList) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = 0; // Reset what was set in maxscaleKeyword + info->type_mask = 0; // Reset what was set in maxscaleKeyword switch (kind) { case MXS_SET_TRANSACTION: if ((scope == TK_GLOBAL) || (scope == TK_SESSION)) { - info->types = QUERY_TYPE_GSYSVAR_WRITE; + info->type_mask = QUERY_TYPE_GSYSVAR_WRITE; } else { ss_dassert(scope == 0); - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; } break; @@ -2405,7 +2405,7 @@ void maxscaleSet(Parse* pParse, int scope, mxs_set_t kind, ExprList* pList) { case TK_CHARACTER: case TK_NAMES: - info->types |= QUERY_TYPE_GSYSVAR_WRITE; + info->type_mask |= QUERY_TYPE_GSYSVAR_WRITE; break; case TK_EQ: @@ -2438,11 +2438,11 @@ void maxscaleSet(Parse* pParse, int scope, mxs_set_t kind, ExprList* pList) if (n_at == 1) { - info->types |= QUERY_TYPE_USERVAR_WRITE; + info->type_mask |= QUERY_TYPE_USERVAR_WRITE; } else { - info->types |= QUERY_TYPE_GSYSVAR_WRITE; + info->type_mask |= QUERY_TYPE_GSYSVAR_WRITE; } // Set pVariable to point to the rightmost part of the name. @@ -2495,13 +2495,13 @@ void maxscaleSet(Parse* pParse, int scope, mxs_set_t kind, ExprList* pList) switch (enable) { case 0: - info->types |= QUERY_TYPE_BEGIN_TRX; - info->types |= QUERY_TYPE_DISABLE_AUTOCOMMIT; + info->type_mask |= QUERY_TYPE_BEGIN_TRX; + info->type_mask |= QUERY_TYPE_DISABLE_AUTOCOMMIT; break; case 1: - info->types |= QUERY_TYPE_ENABLE_AUTOCOMMIT; - info->types |= QUERY_TYPE_COMMIT; + info->type_mask |= QUERY_TYPE_ENABLE_AUTOCOMMIT; + info->type_mask |= QUERY_TYPE_COMMIT; break; default: @@ -2566,7 +2566,7 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) { case MXS_SHOW_COLUMNS: { - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; update_names(info, zDatabase, zName); if (pShow->data == MXS_SHOW_COLUMNS_FULL) { @@ -2594,21 +2594,21 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) case MXS_SHOW_CREATE_VIEW: { - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; update_names(info, zDatabase, zName); } break; case MXS_SHOW_CREATE_TABLE: { - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; update_names(info, zDatabase, zName); } break; case MXS_SHOW_DATABASES: { - info->types = QUERY_TYPE_SHOW_DATABASES; + info->type_mask = QUERY_TYPE_SHOW_DATABASES; update_names(info, "information_schema", "SCHEMATA"); update_field_info(info, "information_schema", "SCHEMATA", "SCHEMA_NAME", u, NULL); } @@ -2618,7 +2618,7 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) case MXS_SHOW_INDEXES: case MXS_SHOW_KEYS: { - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; update_names(info, "information_schema", "STATISTICS"); update_field_info(info, "information_schema", "STATISTICS", "CARDINALITY", u, NULL); update_field_info(info, "information_schema", "STATISTICS", "COLLATION", u, NULL); @@ -2638,7 +2638,7 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) case MXS_SHOW_TABLE_STATUS: { - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; update_names(info, "information_schema", "TABLES"); update_field_info(info, "information_schema", "TABLES", "AUTO_INCREMENT", u, NULL); update_field_info(info, "information_schema", "TABLES", "AVG_ROW_LENGTH", u, NULL); @@ -2669,22 +2669,22 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) case MXS_SHOW_VARIABLES_SESSION: case MXS_SHOW_VARIABLES_UNSPECIFIED: // TODO: qc_mysqlembedded does not set the type bit. - info->types = QUERY_TYPE_UNKNOWN; + info->type_mask = QUERY_TYPE_UNKNOWN; update_names(info, "information_schema", "SESSION_STATUS"); update_field_info(info, "information_schema", "SESSION_STATUS", "VARIABLE_NAME", u, NULL); update_field_info(info, "information_schema", "SESSION_STATUS", "VARIABLE_VALUE", u, NULL); break; case MXS_SHOW_STATUS_MASTER: - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; break; case MXS_SHOW_STATUS_SLAVE: - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; break; case MXS_SHOW_STATUS_ALL_SLAVES: - info->types = QUERY_TYPE_READ; + info->type_mask = QUERY_TYPE_READ; break; default: @@ -2695,7 +2695,7 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) case MXS_SHOW_TABLES: { - info->types = QUERY_TYPE_SHOW_TABLES; + info->type_mask = QUERY_TYPE_SHOW_TABLES; update_names(info, "information_schema", "TABLE_NAMES"); update_field_info(info, "information_schema", "TABLE_NAMES", "TABLE_NAME", u, NULL); } @@ -2705,11 +2705,11 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) { if (pShow->data == MXS_SHOW_VARIABLES_GLOBAL) { - info->types = QUERY_TYPE_GSYSVAR_READ; + info->type_mask = QUERY_TYPE_GSYSVAR_READ; } else { - info->types = QUERY_TYPE_SYSVAR_READ; + info->type_mask = QUERY_TYPE_SYSVAR_READ; } update_names(info, "information_schema", "SESSION_VARIABLES"); update_field_info(info, "information_schema", "SESSION_STATUS", "VARIABLE_NAME", u, NULL); @@ -2720,7 +2720,7 @@ extern void maxscaleShow(Parse* pParse, MxsShow* pShow) case MXS_SHOW_WARNINGS: { // qc_mysqliembedded claims this. - info->types = QUERY_TYPE_WRITE; + info->type_mask = QUERY_TYPE_WRITE; } break; @@ -2737,7 +2737,7 @@ void maxscaleTruncate(Parse* pParse, Token* pDatabase, Token* pName) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); + info->type_mask = (QUERY_TYPE_WRITE | QUERY_TYPE_COMMIT); info->operation = QUERY_OP_TRUNCATE; char* zDatabase; @@ -2769,7 +2769,7 @@ void maxscaleUse(Parse* pParse, Token* pToken) ss_dassert(info); info->status = QC_QUERY_PARSED; - info->types = QUERY_TYPE_SESSION_WRITE; + info->type_mask = QUERY_TYPE_SESSION_WRITE; info->operation = QUERY_OP_CHANGE_DB; } @@ -2782,7 +2782,7 @@ static void qc_sqlite_process_end(void); static int32_t qc_sqlite_thread_init(void); static void qc_sqlite_thread_end(void); static int32_t qc_sqlite_parse(GWBUF* query, int32_t* result); -static int32_t qc_sqlite_get_type(GWBUF* query, uint32_t* typemask); +static int32_t qc_sqlite_get_type_mask(GWBUF* query, uint32_t* typemask); static int32_t qc_sqlite_get_operation(GWBUF* query, int32_t* op); static int32_t qc_sqlite_get_created_table_name(GWBUF* query, char** name); static int32_t qc_sqlite_is_drop_table_query(GWBUF* query, int32_t* is_drop_table); @@ -3019,7 +3019,7 @@ static int32_t qc_sqlite_parse(GWBUF* query, int32_t* result) return info ? QC_RESULT_OK : QC_RESULT_ERROR; } -static int32_t qc_sqlite_get_type(GWBUF* query, uint32_t* type_mask) +static int32_t qc_sqlite_get_type_mask(GWBUF* query, uint32_t* type_mask) { QC_TRACE(); int32_t rv = QC_RESULT_ERROR; @@ -3033,7 +3033,7 @@ static int32_t qc_sqlite_get_type(GWBUF* query, uint32_t* type_mask) { if (qc_info_is_valid(info->status)) { - *type_mask = info->types; + *type_mask = info->type_mask; rv = QC_RESULT_OK; } else if (MXS_LOG_PRIORITY_IS_ENABLED(LOG_INFO)) @@ -3420,7 +3420,7 @@ MXS_MODULE* MXS_CREATE_MODULE() qc_sqlite_thread_init, qc_sqlite_thread_end, qc_sqlite_parse, - qc_sqlite_get_type, + qc_sqlite_get_type_mask, qc_sqlite_get_operation, qc_sqlite_get_created_table_name, qc_sqlite_is_drop_table_query, diff --git a/query_classifier/test/classify.c b/query_classifier/test/classify.c index 7fe74d39d..351b51fdc 100644 --- a/query_classifier/test/classify.c +++ b/query_classifier/test/classify.c @@ -208,7 +208,7 @@ int test(FILE* input, FILE* expected) memmove(strbuff, tok + 1, strsz - qlen); strsz -= qlen; memset(strbuff + strsz, 0, buffsz - strsz); - qc_query_type_t type = qc_get_type(buff); + qc_query_type_t type = qc_get_type_mask(buff); char expbuff[256]; int expos = 0; diff --git a/query_classifier/test/compare.cc b/query_classifier/test/compare.cc index 649d191c8..59a70194f 100644 --- a/query_classifier/test/compare.cc +++ b/query_classifier/test/compare.cc @@ -354,12 +354,12 @@ bool compare_get_type(QUERY_CLASSIFIER* pClassifier1, GWBUF* pCopy1, QUERY_CLASSIFIER* pClassifier2, GWBUF* pCopy2) { bool success = false; - const char HEADING[] = "qc_get_type : "; + const char HEADING[] = "qc_get_type_mask : "; uint32_t rv1; - pClassifier1->qc_get_type(pCopy1, &rv1); + pClassifier1->qc_get_type_mask(pCopy1, &rv1); uint32_t rv2; - pClassifier2->qc_get_type(pCopy2, &rv2); + pClassifier2->qc_get_type_mask(pCopy2, &rv2); stringstream ss; ss << HEADING; @@ -1186,10 +1186,10 @@ bool compare(QUERY_CLASSIFIER* pClassifier1, GWBUF* pBuf1, bool success = (errors == 0); uint32_t type_mask1; - pClassifier1->qc_get_type(pBuf1, &type_mask1); + pClassifier1->qc_get_type_mask(pBuf1, &type_mask1); uint32_t type_mask2; - pClassifier2->qc_get_type(pBuf2, &type_mask2); + pClassifier2->qc_get_type_mask(pBuf2, &type_mask2); if ((type_mask1 == type_mask2) && ((type_mask1 & QUERY_TYPE_PREPARE_NAMED_STMT) || (type_mask1 & QUERY_TYPE_PREPARE_STMT))) diff --git a/server/core/query_classifier.c b/server/core/query_classifier.c index 58604d85d..404fd49e5 100644 --- a/server/core/query_classifier.c +++ b/server/core/query_classifier.c @@ -133,14 +133,14 @@ qc_parse_result_t qc_parse(GWBUF* query) return (qc_parse_result_t)result; } -uint32_t qc_get_type(GWBUF* query) +uint32_t qc_get_type_mask(GWBUF* query) { QC_TRACE(); ss_dassert(classifier); uint32_t type_mask = QUERY_TYPE_UNKNOWN; - classifier->qc_get_type(query, &type_mask); + classifier->qc_get_type_mask(query, &type_mask); return type_mask; } diff --git a/server/modules/filter/dbfwfilter/dbfwfilter.c b/server/modules/filter/dbfwfilter/dbfwfilter.c index 3e983268e..b9a7557ff 100644 --- a/server/modules/filter/dbfwfilter/dbfwfilter.c +++ b/server/modules/filter/dbfwfilter/dbfwfilter.c @@ -2337,7 +2337,7 @@ routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *session, GWBUF *queue) if (modutil_is_SQL(queue) || modutil_is_SQL_prepare(queue)) { - type = qc_get_type(queue); + type = qc_get_type_mask(queue); } if (modutil_is_SQL(queue) && modutil_count_statements(queue) > 1) diff --git a/server/modules/filter/luafilter/luafilter.c b/server/modules/filter/luafilter/luafilter.c index cf38af3f9..f40832f95 100644 --- a/server/modules/filter/luafilter/luafilter.c +++ b/server/modules/filter/luafilter/luafilter.c @@ -127,14 +127,14 @@ static int id_gen(lua_State* state) return 1; } -static int lua_qc_get_type(lua_State* state) +static int lua_qc_get_type_mask(lua_State* state) { int ibuf = lua_upvalueindex(1); GWBUF *buf = *((GWBUF**)lua_touserdata(state, ibuf)); if (buf) { - uint32_t type = qc_get_type(buf); + uint32_t type = qc_get_type_mask(buf); char *mask = qc_typemask_to_string(type); lua_pushstring(state, mask); MXS_FREE(mask); @@ -243,8 +243,8 @@ createInstance(const char *name, char **options, CONFIG_PARAMETER *params) /** Expose a part of the query classifier API */ lua_pushlightuserdata(my_instance->global_lua_state, ¤t_global_query); - lua_pushcclosure(my_instance->global_lua_state, lua_qc_get_type, 1); - lua_setglobal(my_instance->global_lua_state, "lua_qc_get_type"); + lua_pushcclosure(my_instance->global_lua_state, lua_qc_get_type_mask, 1); + lua_setglobal(my_instance->global_lua_state, "lua_qc_get_type_mask"); lua_pushlightuserdata(my_instance->global_lua_state, ¤t_global_query); lua_pushcclosure(my_instance->global_lua_state, lua_qc_get_operation, 1); @@ -314,8 +314,8 @@ static MXS_FILTER_SESSION *newSession(MXS_FILTER *instance, MXS_SESSION *session /** Expose a part of the query classifier API */ lua_pushlightuserdata(my_session->lua_state, &my_session->current_query); - lua_pushcclosure(my_session->lua_state, lua_qc_get_type, 1); - lua_setglobal(my_session->lua_state, "lua_qc_get_type"); + lua_pushcclosure(my_session->lua_state, lua_qc_get_type_mask, 1); + lua_setglobal(my_session->lua_state, "lua_qc_get_type_mask"); lua_pushlightuserdata(my_session->lua_state, &my_session->current_query); lua_pushcclosure(my_session->lua_state, lua_qc_get_operation, 1); diff --git a/server/modules/filter/tpmfilter/tpmfilter.c b/server/modules/filter/tpmfilter/tpmfilter.c index 4dd21f950..bae42e3b9 100644 --- a/server/modules/filter/tpmfilter/tpmfilter.c +++ b/server/modules/filter/tpmfilter/tpmfilter.c @@ -439,7 +439,7 @@ routeQuery(MXS_FILTER *instance, MXS_FILTER_SESSION *session, GWBUF *queue) { if ((ptr = modutil_get_SQL(queue)) != NULL) { - uint32_t query_type = qc_get_type(queue); + uint32_t query_type = qc_get_type_mask(queue); int query_len = strlen(ptr); my_session->query_end = false; diff --git a/server/modules/protocol/MySQL/MySQLClient/mysql_client.c b/server/modules/protocol/MySQL/MySQLClient/mysql_client.c index 43439dbe3..ae7ff1256 100644 --- a/server/modules/protocol/MySQL/MySQLClient/mysql_client.c +++ b/server/modules/protocol/MySQL/MySQLClient/mysql_client.c @@ -1485,7 +1485,7 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF if (MYSQL_GET_COMMAND(data) == MYSQL_COM_QUERY) { - uint32_t type = qc_get_type(packetbuf); + uint32_t type = qc_get_type_mask(packetbuf); if (type & QUERY_TYPE_BEGIN_TRX) { diff --git a/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c b/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c index f3ec8fa63..8d110649d 100644 --- a/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c +++ b/server/modules/routing/readwritesplit/rwsplit_tmp_table_multi.c @@ -392,11 +392,11 @@ determine_query_type(GWBUF *querybuf, int packet_type, bool non_empty_packet) break; case MYSQL_COM_QUERY: - qtype = qc_get_type(querybuf); + qtype = qc_get_type_mask(querybuf); break; case MYSQL_COM_STMT_PREPARE: - qtype = qc_get_type(querybuf); + qtype = qc_get_type_mask(querybuf); qtype |= QUERY_TYPE_PREPARE_STMT; break; diff --git a/server/modules/routing/schemarouter/schemarouter.c b/server/modules/routing/schemarouter/schemarouter.c index 628e5093f..a36c2db38 100644 --- a/server/modules/routing/schemarouter/schemarouter.c +++ b/server/modules/routing/schemarouter/schemarouter.c @@ -1765,12 +1765,12 @@ static int routeQuery(ROUTER* instance, break; case MYSQL_COM_QUERY: - qtype = qc_get_type(querybuf); + qtype = qc_get_type_mask(querybuf); op = qc_get_operation(querybuf); break; case MYSQL_COM_STMT_PREPARE: - qtype = qc_get_type(querybuf); + qtype = qc_get_type_mask(querybuf); qtype |= QUERY_TYPE_PREPARE_STMT; break;