MXS-1364 Drop the usage field

But for the most trivial statements did not really provide
useful information.

The arguments of the "function" '=' are now reported.
This commit is contained in:
Johan Wikman
2017-08-23 14:21:04 +03:00
parent 4c100a305e
commit ad4e8dad94
14 changed files with 330 additions and 649 deletions

View File

@ -352,141 +352,6 @@ GWBUF* qc_get_preparable_stmt(GWBUF* stmt)
return preparable_stmt;
}
struct type_name_info field_usage_to_type_name_info(qc_field_usage_t usage)
{
struct type_name_info info;
switch (usage)
{
case QC_USED_IN_SELECT:
{
static const char name[] = "QC_USED_IN_SELECT";
info.name = name;
info.name_len = sizeof(name) - 1;
}
break;
case QC_USED_IN_SUBSELECT:
{
static const char name[] = "QC_USED_IN_SUBSELECT";
info.name = name;
info.name_len = sizeof(name) - 1;
}
break;
case QC_USED_IN_WHERE:
{
static const char name[] = "QC_USED_IN_WHERE";
info.name = name;
info.name_len = sizeof(name) - 1;
}
break;
case QC_USED_IN_SET:
{
static const char name[] = "QC_USED_IN_SET";
info.name = name;
info.name_len = sizeof(name) - 1;
}
break;
case QC_USED_IN_GROUP_BY:
{
static const char name[] = "QC_USED_IN_GROUP_BY";
info.name = name;
info.name_len = sizeof(name) - 1;
}
break;
default:
{
static const char name[] = "UNKNOWN_FIELD_USAGE";
info.name = name;
info.name_len = sizeof(name) - 1;
}
break;
}
return info;
}
const char* qc_field_usage_to_string(qc_field_usage_t usage)
{
return field_usage_to_type_name_info(usage).name;
}
static const qc_field_usage_t FIELD_USAGE_VALUES[] =
{
QC_USED_IN_SELECT,
QC_USED_IN_SUBSELECT,
QC_USED_IN_WHERE,
QC_USED_IN_SET,
QC_USED_IN_GROUP_BY,
};
static const int N_FIELD_USAGE_VALUES =
sizeof(FIELD_USAGE_VALUES) / sizeof(FIELD_USAGE_VALUES[0]);
static const int FIELD_USAGE_MAX_LEN = 20; // strlen("QC_USED_IN_SUBSELECT");
char* qc_field_usage_mask_to_string(uint32_t mask)
{
size_t len = 0;
// First calculate how much space will be needed.
for (int i = 0; i < N_FIELD_USAGE_VALUES; ++i)
{
if (mask & FIELD_USAGE_VALUES[i])
{
if (len != 0)
{
++len; // strlen("|");
}
len += FIELD_USAGE_MAX_LEN;
}
}
++len;
// Then make one allocation and build the string.
char* s = (char*) MXS_MALLOC(len);
if (s)
{
if (len > 1)
{
char* p = s;
for (int i = 0; i < N_FIELD_USAGE_VALUES; ++i)
{
qc_field_usage_t value = FIELD_USAGE_VALUES[i];
if (mask & value)
{
if (p != s)
{
strcpy(p, "|");
++p;
}
struct type_name_info info = field_usage_to_type_name_info(value);
strcpy(p, info.name);
p += info.name_len;
}
}
}
else
{
*s = 0;
}
}
return s;
}
const char* qc_op_to_string(qc_query_op_t op)
{
switch (op)

View File

@ -1144,55 +1144,52 @@ static bool cache_rule_matches_column_regexp(CACHE_RULE *self,
{
const QC_FIELD_INFO *info = (infos + i);
if (info->usage & QC_USED_IN_SELECT)
size_t database_len;
const char *database;
if (info->database)
{
size_t database_len;
const char *database;
if (info->database)
{
database = info->database;
database_len = strlen(info->database);
}
else
{
database = default_database;
database_len = default_database_len;
}
size_t table_len;
const char *table;
if (info->table)
{
table = info->table;
table_len = strlen(info->table);
}
else
{
table = default_table;
table_len = default_table_len;
}
char buffer[database_len + 1 + table_len + strlen(info->column) + 1];
buffer[0] = 0;
if (database)
{
strcat(buffer, database);
strcat(buffer, ".");
}
if (table)
{
strcat(buffer, table);
strcat(buffer, ".");
}
strcat(buffer, info->column);
matches = cache_rule_compare(self, thread_id, buffer);
database = info->database;
database_len = strlen(info->database);
}
else
{
database = default_database;
database_len = default_database_len;
}
size_t table_len;
const char *table;
if (info->table)
{
table = info->table;
table_len = strlen(info->table);
}
else
{
table = default_table;
table_len = default_table_len;
}
char buffer[database_len + 1 + table_len + strlen(info->column) + 1];
buffer[0] = 0;
if (database)
{
strcat(buffer, database);
strcat(buffer, ".");
}
if (table)
{
strcat(buffer, table);
strcat(buffer, ".");
}
strcat(buffer, info->column);
matches = cache_rule_compare(self, thread_id, buffer);
++i;
}
@ -1280,84 +1277,81 @@ static bool cache_rule_matches_column_simple(CACHE_RULE *self, const char *defau
{
const QC_FIELD_INFO *info = (infos + i);
if (info->usage & QC_USED_IN_SELECT)
if ((strcasecmp(info->column, rule_column) == 0) || strcmp(rule_column, "*") == 0)
{
if ((strcasecmp(info->column, rule_column) == 0) || strcmp(rule_column, "*") == 0)
if (rule_table)
{
if (rule_table)
const char* check_table = info->table ? info->table : default_table;
if (check_table)
{
const char* check_table = info->table ? info->table : default_table;
if (check_table)
if (strcasecmp(check_table, rule_table) == 0)
{
if (strcasecmp(check_table, rule_table) == 0)
if (rule_database)
{
if (rule_database)
{
const char *check_database =
info->database ? info->database : default_database;
const char *check_database =
info->database ? info->database : default_database;
if (check_database)
if (check_database)
{
if (strcasecmp(check_database, rule_database) == 0)
{
if (strcasecmp(check_database, rule_database) == 0)
{
// The column, table and database matched.
matches = true;
}
else
{
// The column, table matched but the database did not.
matches = false;
}
// The column, table and database matched.
matches = true;
}
else
{
// If the rules specify a database but we do not know the database,
// we consider the databases not to match.
// The column, table matched but the database did not.
matches = false;
}
}
else
{
// If the rule specifies no database, then if the column and the table
// matches, the rule matches.
matches = true;
// If the rules specify a database but we do not know the database,
// we consider the databases not to match.
matches = false;
}
}
else
{
// The column matched, but the table did not.
matches = false;
// If the rule specifies no database, then if the column and the table
// matches, the rule matches.
matches = true;
}
}
else
{
// If the rules specify a table but we do not know the table, we
// consider the tables not to match.
// The column matched, but the table did not.
matches = false;
}
}
else
{
// The column matched and there is no table rule.
matches = true;
// If the rules specify a table but we do not know the table, we
// consider the tables not to match.
matches = false;
}
}
else
{
// The column did not match.
matches = false;
}
if (self->op == CACHE_OP_NEQ)
{
matches = !matches;
// The column matched and there is no table rule.
matches = true;
}
}
else
{
// The column did not match.
matches = false;
}
++i;
if (self->op == CACHE_OP_NEQ)
{
matches = !matches;
}
}
++i;
if (tables)
{
for (i = 0; i < (size_t)n_tables; ++i)