Introduce new qc_parse() prototype
It is now possible to specify what information the caller is interested in. With this the cost for collecting information during the query parsing that nobody is interested in can be avoided.
This commit is contained in:
parent
441b0204bf
commit
d0a9571da0
@ -29,6 +29,18 @@ typedef enum qc_init_kind
|
||||
QC_INIT_BOTH = 0x03
|
||||
} qc_init_kind_t;
|
||||
|
||||
/**
|
||||
* @c qc_collect_info_t specifies what information should be collected during parsing.
|
||||
*/
|
||||
typedef enum qc_collect_info
|
||||
{
|
||||
QC_COLLECT_TABLES = 0x01, /*< Collect table names. */
|
||||
QC_COLLECT_DATABASES = 0x02, /*< Collect database names. */
|
||||
QC_COLLECT_FIELDS = 0x04, /*< Collect field information. */
|
||||
QC_COLLECT_FUNCTIONS = 0x08, /*< Collect function information. */
|
||||
|
||||
QC_COLLECT_ALL = (QC_COLLECT_TABLES|QC_COLLECT_DATABASES|QC_COLLECT_FIELDS|QC_COLLECT_FUNCTIONS)
|
||||
} qc_collect_info_t;
|
||||
/**
|
||||
* qc_query_type_t defines bits that provide information about a
|
||||
* particular statement.
|
||||
@ -196,13 +208,16 @@ typedef struct query_classifier
|
||||
/**
|
||||
* Called to explicitly parse a statement.
|
||||
*
|
||||
* @param stmt The statement to be parsed.
|
||||
* @param result On return, the parse result, if @c QC_RESULT_OK is returned.
|
||||
* @param stmt The statement to be parsed.
|
||||
* @param collect A bitmask of @c qc_collect_info_t values. Specifies what information
|
||||
* should be collected. Only a hint and must not restrict what information
|
||||
* later can be queried.
|
||||
* @param result On return, the parse result, if @c QC_RESULT_OK is returned.
|
||||
*
|
||||
* @return QC_RESULT_OK, if the parsing was not aborted due to resource
|
||||
* exhaustion or equivalent.
|
||||
*/
|
||||
int32_t (*qc_parse)(GWBUF* stmt, int32_t* result);
|
||||
int32_t (*qc_parse)(GWBUF* stmt, uint32_t collect, int32_t* result);
|
||||
|
||||
/**
|
||||
* Reports the type of the statement.
|
||||
@ -476,11 +491,17 @@ void qc_thread_end(uint32_t kind);
|
||||
* already then this function will only return the result of that parsing;
|
||||
* the statement will not be parsed again.
|
||||
*
|
||||
* @param stmt A buffer containing an COM_QUERY or COM_STMT_PREPARE packet.
|
||||
* @param stmt A buffer containing an COM_QUERY or COM_STMT_PREPARE packet.
|
||||
* @param collect A bitmask of @c qc_collect_info_t values. Specifies what information
|
||||
* should be collected.
|
||||
*
|
||||
* Note that this is merely a hint and does not restrict what
|
||||
* information can be queried for. If necessary, the statement
|
||||
* will transparently be reparsed.
|
||||
*
|
||||
* @return To what extent the statement could be parsed.
|
||||
*/
|
||||
qc_parse_result_t qc_parse(GWBUF* stmt);
|
||||
qc_parse_result_t qc_parse(GWBUF* stmt, uint32_t collect);
|
||||
|
||||
/**
|
||||
* Convert a qc_field_usage_t enum to corresponding string.
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "../../server/core/maxscale/config.h"
|
||||
|
||||
int32_t qc_dummy_parse(GWBUF* querybuf, int32_t* pResult)
|
||||
int32_t qc_dummy_parse(GWBUF* querybuf, uint32_t collect, int32_t* pResult)
|
||||
{
|
||||
*pResult = QC_QUERY_INVALID;
|
||||
return QC_RESULT_OK;
|
||||
|
@ -136,7 +136,7 @@ bool ensure_query_is_parsed(GWBUF* query)
|
||||
return parsed;
|
||||
}
|
||||
|
||||
int32_t qc_mysql_parse(GWBUF* querybuf, int32_t* result)
|
||||
int32_t qc_mysql_parse(GWBUF* querybuf, uint32_t collect, int32_t* result)
|
||||
{
|
||||
bool parsed = ensure_query_is_parsed(querybuf);
|
||||
|
||||
|
@ -2792,7 +2792,7 @@ static int32_t qc_sqlite_process_init(void);
|
||||
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_parse(GWBUF* query, uint32_t collect, int32_t* result);
|
||||
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);
|
||||
@ -3010,7 +3010,7 @@ static void qc_sqlite_thread_end(void)
|
||||
this_thread.initialized = false;
|
||||
}
|
||||
|
||||
static int32_t qc_sqlite_parse(GWBUF* query, int32_t* result)
|
||||
static int32_t qc_sqlite_parse(GWBUF* query, uint32_t collect, int32_t* result)
|
||||
{
|
||||
QC_TRACE();
|
||||
ss_dassert(this_unit.initialized);
|
||||
|
@ -312,13 +312,13 @@ bool compare_parse(QUERY_CLASSIFIER* pClassifier1, GWBUF* pCopy1,
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
||||
int32_t rv1;
|
||||
pClassifier1->qc_parse(pCopy1, &rv1);
|
||||
pClassifier1->qc_parse(pCopy1, QC_COLLECT_ALL, &rv1);
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &finish);
|
||||
update_time(&global.time1, start, finish);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
|
||||
int32_t rv2;
|
||||
pClassifier2->qc_parse(pCopy2, &rv2);
|
||||
pClassifier2->qc_parse(pCopy2, QC_COLLECT_ALL, &rv2);
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &finish);
|
||||
update_time(&global.time2, start, finish);
|
||||
|
||||
|
@ -51,7 +51,7 @@ int main()
|
||||
// being of the opinion that the statement was not the one to be
|
||||
// classified and hence an alien parse-tree being passed to sqlite3's
|
||||
// code generator.
|
||||
qc_parse(stmt);
|
||||
qc_parse(stmt, QC_COLLECT_ALL);
|
||||
|
||||
qc_process_end(QC_INIT_BOTH);
|
||||
|
||||
|
@ -178,14 +178,14 @@ void qc_thread_end(uint32_t kind)
|
||||
}
|
||||
}
|
||||
|
||||
qc_parse_result_t qc_parse(GWBUF* query)
|
||||
qc_parse_result_t qc_parse(GWBUF* query, uint32_t collect)
|
||||
{
|
||||
QC_TRACE();
|
||||
ss_dassert(classifier);
|
||||
|
||||
int32_t result = QC_QUERY_INVALID;
|
||||
|
||||
classifier->qc_parse(query, &result);
|
||||
classifier->qc_parse(query, collect, &result);
|
||||
|
||||
return (qc_parse_result_t)result;
|
||||
}
|
||||
|
@ -2007,7 +2007,7 @@ bool rule_matches(FW_INSTANCE* my_instance,
|
||||
|
||||
if (is_sql)
|
||||
{
|
||||
qc_parse_result_t parse_result = qc_parse(queue);
|
||||
qc_parse_result_t parse_result = qc_parse(queue, QC_COLLECT_ALL);
|
||||
|
||||
if (parse_result == QC_QUERY_INVALID)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user