Bug#49501 Inefficient information_schema check (system collation)
added check_length optimization for I_S_NAME comparison
This commit is contained in:
parent
22cff39274
commit
baacdf1dae
@ -1401,7 +1401,7 @@ Event_job_data::execute(THD *thd, bool drop)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (check_access(thd, EVENT_ACL, dbname.str,
|
if (check_access(thd, EVENT_ACL, dbname.str,
|
||||||
0, 0, 0, is_schema_db(dbname.str)))
|
0, 0, 0, is_schema_db(dbname.str, dbname.length)))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
This aspect of behavior is defined in the worklog,
|
This aspect of behavior is defined in the worklog,
|
||||||
|
@ -415,7 +415,8 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
|
|||||||
DBUG_ASSERT(parse_data->expression || parse_data->execute_at);
|
DBUG_ASSERT(parse_data->expression || parse_data->execute_at);
|
||||||
|
|
||||||
if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0,
|
if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0,
|
||||||
is_schema_db(parse_data->dbname.str)))
|
is_schema_db(parse_data->dbname.str,
|
||||||
|
parse_data->dbname.length)))
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
if (check_db_dir_existence(parse_data->dbname.str))
|
if (check_db_dir_existence(parse_data->dbname.str))
|
||||||
@ -526,7 +527,8 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
|
|||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0,
|
if (check_access(thd, EVENT_ACL, parse_data->dbname.str, 0, 0, 0,
|
||||||
is_schema_db(parse_data->dbname.str)))
|
is_schema_db(parse_data->dbname.str,
|
||||||
|
parse_data->dbname.length)))
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
if (new_dbname) /* It's a rename */
|
if (new_dbname) /* It's a rename */
|
||||||
@ -548,7 +550,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
|
|||||||
access it.
|
access it.
|
||||||
*/
|
*/
|
||||||
if (check_access(thd, EVENT_ACL, new_dbname->str, 0, 0, 0,
|
if (check_access(thd, EVENT_ACL, new_dbname->str, 0, 0, 0,
|
||||||
is_schema_db(new_dbname->str)))
|
is_schema_db(new_dbname->str, new_dbname->length)))
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
/* Check that the target database exists */
|
/* Check that the target database exists */
|
||||||
@ -653,7 +655,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
|
|||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0,
|
if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0,
|
||||||
is_schema_db(dbname.str)))
|
is_schema_db(dbname.str, dbname.length)))
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -811,7 +813,7 @@ Events::show_create_event(THD *thd, LEX_STRING dbname, LEX_STRING name)
|
|||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0,
|
if (check_access(thd, EVENT_ACL, dbname.str, 0, 0, 0,
|
||||||
is_schema_db(dbname.str)))
|
is_schema_db(dbname.str, dbname.length)))
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -869,7 +871,8 @@ Events::fill_schema_events(THD *thd, TABLE_LIST *tables, COND * /* cond */)
|
|||||||
if (thd->lex->sql_command == SQLCOM_SHOW_EVENTS)
|
if (thd->lex->sql_command == SQLCOM_SHOW_EVENTS)
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(thd->lex->select_lex.db);
|
DBUG_ASSERT(thd->lex->select_lex.db);
|
||||||
if (!is_schema_db(thd->lex->select_lex.db) && // There is no events in I_S
|
if (!is_schema_db(thd->lex->select_lex.db, // There is no events in I_S
|
||||||
|
strlen(thd->lex->select_lex.db)) &&
|
||||||
check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0, 0))
|
check_access(thd, EVENT_ACL, thd->lex->select_lex.db, 0, 0, 0, 0))
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
db= thd->lex->select_lex.db;
|
db= thd->lex->select_lex.db;
|
||||||
|
@ -1415,8 +1415,12 @@ bool get_schema_tables_result(JOIN *join,
|
|||||||
enum enum_schema_table_state executed_place);
|
enum enum_schema_table_state executed_place);
|
||||||
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
|
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
|
||||||
|
|
||||||
#define is_schema_db(X) \
|
inline bool is_schema_db(const char *name, size_t len)
|
||||||
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
|
{
|
||||||
|
return (INFORMATION_SCHEMA_NAME.length == len &&
|
||||||
|
!my_strcasecmp(system_charset_info,
|
||||||
|
INFORMATION_SCHEMA_NAME.str, name));
|
||||||
|
}
|
||||||
|
|
||||||
/* sql_prepare.cc */
|
/* sql_prepare.cc */
|
||||||
|
|
||||||
|
@ -905,7 +905,7 @@ bool load_master_data(THD* thd)
|
|||||||
if (!rpl_filter->db_ok(db) ||
|
if (!rpl_filter->db_ok(db) ||
|
||||||
!rpl_filter->db_ok_with_wild_table(db) ||
|
!rpl_filter->db_ok_with_wild_table(db) ||
|
||||||
!strcmp(db,"mysql") ||
|
!strcmp(db,"mysql") ||
|
||||||
is_schema_db(db))
|
is_schema_db(db, strlen(db)))
|
||||||
{
|
{
|
||||||
*cur_table_res = 0;
|
*cur_table_res = 0;
|
||||||
continue;
|
continue;
|
||||||
|
@ -618,7 +618,7 @@ int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info,
|
|||||||
DBUG_ENTER("mysql_create_db");
|
DBUG_ENTER("mysql_create_db");
|
||||||
|
|
||||||
/* do not create 'information_schema' db */
|
/* do not create 'information_schema' db */
|
||||||
if (!my_strcasecmp(system_charset_info, db, INFORMATION_SCHEMA_NAME.str))
|
if (is_schema_db(db, strlen(db)))
|
||||||
{
|
{
|
||||||
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
|
my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
|
||||||
DBUG_RETURN(-1);
|
DBUG_RETURN(-1);
|
||||||
@ -1557,8 +1557,7 @@ bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name, bool force_switch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (my_strcasecmp(system_charset_info, new_db_name->str,
|
if (is_schema_db(new_db_name->str, new_db_name->length))
|
||||||
INFORMATION_SCHEMA_NAME.str) == 0)
|
|
||||||
{
|
{
|
||||||
/* Switch the current database to INFORMATION_SCHEMA. */
|
/* Switch the current database to INFORMATION_SCHEMA. */
|
||||||
|
|
||||||
|
@ -1305,8 +1305,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
|||||||
table_list.alias= table_list.table_name= conv_name.str;
|
table_list.alias= table_list.table_name= conv_name.str;
|
||||||
packet= arg_end + 1;
|
packet= arg_end + 1;
|
||||||
|
|
||||||
if (!my_strcasecmp(system_charset_info, table_list.db,
|
if (is_schema_db(table_list.db, table_list.db_length))
|
||||||
INFORMATION_SCHEMA_NAME.str))
|
|
||||||
{
|
{
|
||||||
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, table_list.alias);
|
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, table_list.alias);
|
||||||
if (schema_table)
|
if (schema_table)
|
||||||
@ -1368,7 +1367,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (check_access(thd, CREATE_ACL, db.str , 0, 1, 0,
|
if (check_access(thd, CREATE_ACL, db.str , 0, 1, 0,
|
||||||
is_schema_db(db.str)))
|
is_schema_db(db.str, db.length)))
|
||||||
break;
|
break;
|
||||||
general_log_print(thd, command, "%.*s", db.length, db.str);
|
general_log_print(thd, command, "%.*s", db.length, db.str);
|
||||||
bzero(&create_info, sizeof(create_info));
|
bzero(&create_info, sizeof(create_info));
|
||||||
@ -1387,7 +1386,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
|||||||
my_error(ER_WRONG_DB_NAME, MYF(0), db.str ? db.str : "NULL");
|
my_error(ER_WRONG_DB_NAME, MYF(0), db.str ? db.str : "NULL");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (check_access(thd, DROP_ACL, db.str, 0, 1, 0, is_schema_db(db.str)))
|
if (check_access(thd, DROP_ACL, db.str, 0, 1, 0,
|
||||||
|
is_schema_db(db.str, db.length)))
|
||||||
break;
|
break;
|
||||||
if (thd->locked_tables || thd->active_transaction())
|
if (thd->locked_tables || thd->active_transaction())
|
||||||
{
|
{
|
||||||
@ -2852,7 +2852,7 @@ end_with_restore_list:
|
|||||||
&first_table->grant.privilege, 0, 0,
|
&first_table->grant.privilege, 0, 0,
|
||||||
test(first_table->schema_table)) ||
|
test(first_table->schema_table)) ||
|
||||||
check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0,
|
check_access(thd,INSERT_ACL | CREATE_ACL,select_lex->db,&priv,0,0,
|
||||||
is_schema_db(select_lex->db))||
|
is_schema_db(select_lex->db, strlen(select_lex->db)))||
|
||||||
check_merge_table_access(thd, first_table->db,
|
check_merge_table_access(thd, first_table->db,
|
||||||
(TABLE_LIST *)
|
(TABLE_LIST *)
|
||||||
create_info.merge_list.first))
|
create_info.merge_list.first))
|
||||||
@ -3590,7 +3590,7 @@ end_with_restore_list:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (check_access(thd,CREATE_ACL,lex->name.str, 0, 1, 0,
|
if (check_access(thd,CREATE_ACL,lex->name.str, 0, 1, 0,
|
||||||
is_schema_db(lex->name.str)))
|
is_schema_db(lex->name.str, lex->name.length)))
|
||||||
break;
|
break;
|
||||||
res= mysql_create_db(thd,(lower_case_table_names == 2 ? alias :
|
res= mysql_create_db(thd,(lower_case_table_names == 2 ? alias :
|
||||||
lex->name.str), &create_info, 0);
|
lex->name.str), &create_info, 0);
|
||||||
@ -3625,7 +3625,7 @@ end_with_restore_list:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (check_access(thd,DROP_ACL,lex->name.str,0,1,0,
|
if (check_access(thd,DROP_ACL,lex->name.str,0,1,0,
|
||||||
is_schema_db(lex->name.str)))
|
is_schema_db(lex->name.str, lex->name.length)))
|
||||||
break;
|
break;
|
||||||
if (thd->locked_tables || thd->active_transaction())
|
if (thd->locked_tables || thd->active_transaction())
|
||||||
{
|
{
|
||||||
@ -3659,9 +3659,12 @@ end_with_restore_list:
|
|||||||
my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
|
my_error(ER_WRONG_DB_NAME, MYF(0), db->str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0, is_schema_db(db->str)) ||
|
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0,
|
||||||
check_access(thd, DROP_ACL, db->str, 0, 1, 0, is_schema_db(db->str)) ||
|
is_schema_db(db->str, db->length)) ||
|
||||||
check_access(thd, CREATE_ACL, db->str, 0, 1, 0, is_schema_db(db->str)))
|
check_access(thd, DROP_ACL, db->str, 0, 1, 0,
|
||||||
|
is_schema_db(db->str, db->length)) ||
|
||||||
|
check_access(thd, CREATE_ACL, db->str, 0, 1, 0,
|
||||||
|
is_schema_db(db->str, db->length)))
|
||||||
{
|
{
|
||||||
res= 1;
|
res= 1;
|
||||||
break;
|
break;
|
||||||
@ -3704,7 +3707,8 @@ end_with_restore_list:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0, is_schema_db(db->str)))
|
if (check_access(thd, ALTER_ACL, db->str, 0, 1, 0,
|
||||||
|
is_schema_db(db->str, db->length)))
|
||||||
break;
|
break;
|
||||||
if (thd->locked_tables || thd->active_transaction())
|
if (thd->locked_tables || thd->active_transaction())
|
||||||
{
|
{
|
||||||
@ -3860,7 +3864,8 @@ end_with_restore_list:
|
|||||||
first_table ? &first_table->grant.privilege : 0,
|
first_table ? &first_table->grant.privilege : 0,
|
||||||
first_table ? 0 : 1, 0,
|
first_table ? 0 : 1, 0,
|
||||||
first_table ? (bool) first_table->schema_table :
|
first_table ? (bool) first_table->schema_table :
|
||||||
select_lex->db ? is_schema_db(select_lex->db) : 0))
|
select_lex->db ?
|
||||||
|
is_schema_db(select_lex->db, strlen(select_lex->db)) : 0))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (thd->security_ctx->user) // If not replication
|
if (thd->security_ctx->user) // If not replication
|
||||||
@ -4203,7 +4208,8 @@ end_with_restore_list:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str, 0, 0, 0,
|
if (check_access(thd, CREATE_PROC_ACL, lex->sphead->m_db.str, 0, 0, 0,
|
||||||
is_schema_db(lex->sphead->m_db.str)))
|
is_schema_db(lex->sphead->m_db.str,
|
||||||
|
lex->sphead->m_db.length)))
|
||||||
goto create_sp_error;
|
goto create_sp_error;
|
||||||
|
|
||||||
if (end_active_trans(thd))
|
if (end_active_trans(thd))
|
||||||
@ -4858,7 +4864,8 @@ create_sp_error:
|
|||||||
res= mysql_xa_recover(thd);
|
res= mysql_xa_recover(thd);
|
||||||
break;
|
break;
|
||||||
case SQLCOM_ALTER_TABLESPACE:
|
case SQLCOM_ALTER_TABLESPACE:
|
||||||
if (check_access(thd, ALTER_ACL, thd->db, 0, 1, 0, thd->db ? is_schema_db(thd->db) : 0))
|
if (check_access(thd, ALTER_ACL, thd->db, 0, 1, 0,
|
||||||
|
thd->db ? is_schema_db(thd->db, thd->db_length) : 0))
|
||||||
break;
|
break;
|
||||||
if (!(res= mysql_alter_tablespace(thd, lex->alter_tablespace_info)))
|
if (!(res= mysql_alter_tablespace(thd, lex->alter_tablespace_info)))
|
||||||
my_ok(thd);
|
my_ok(thd);
|
||||||
@ -5297,7 +5304,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table)
|
|||||||
|
|
||||||
if (check_access(thd, SELECT_ACL, dst_db_name,
|
if (check_access(thd, SELECT_ACL, dst_db_name,
|
||||||
&thd->col_access, FALSE, FALSE,
|
&thd->col_access, FALSE, FALSE,
|
||||||
is_schema_db(dst_db_name)))
|
is_schema_db(dst_db_name, strlen(dst_db_name))))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (!thd->col_access && check_grant_db(thd, dst_db_name))
|
if (!thd->col_access && check_grant_db(thd, dst_db_name))
|
||||||
@ -6262,8 +6269,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
|
|||||||
ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX);
|
ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX);
|
||||||
ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES);
|
ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES);
|
||||||
ptr->derived= table->sel;
|
ptr->derived= table->sel;
|
||||||
if (!ptr->derived && !my_strcasecmp(system_charset_info, ptr->db,
|
if (!ptr->derived && is_schema_db(ptr->db, ptr->db_length))
|
||||||
INFORMATION_SCHEMA_NAME.str))
|
|
||||||
{
|
{
|
||||||
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->table_name);
|
ST_SCHEMA_TABLE *schema_table= find_schema_table(thd, ptr->table_name);
|
||||||
if (!schema_table ||
|
if (!schema_table ||
|
||||||
|
@ -826,8 +826,7 @@ bool mysqld_show_create_db(THD *thd, char *dbname,
|
|||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!my_strcasecmp(system_charset_info, dbname,
|
if (is_schema_db(dbname, strlen(dbname)))
|
||||||
INFORMATION_SCHEMA_NAME.str))
|
|
||||||
{
|
{
|
||||||
dbname= INFORMATION_SCHEMA_NAME.str;
|
dbname= INFORMATION_SCHEMA_NAME.str;
|
||||||
create.default_table_charset= system_charset_info;
|
create.default_table_charset= system_charset_info;
|
||||||
@ -2780,8 +2779,8 @@ int make_db_list(THD *thd, List<LEX_STRING> *files,
|
|||||||
*/
|
*/
|
||||||
if (lookup_field_vals->db_value.str)
|
if (lookup_field_vals->db_value.str)
|
||||||
{
|
{
|
||||||
if (!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str,
|
if (is_schema_db(lookup_field_vals->db_value.str,
|
||||||
lookup_field_vals->db_value.str))
|
lookup_field_vals->db_value.length))
|
||||||
{
|
{
|
||||||
*with_i_schema= 1;
|
*with_i_schema= 1;
|
||||||
if (files->push_back(i_s_name_copy))
|
if (files->push_back(i_s_name_copy))
|
||||||
@ -5228,7 +5227,7 @@ copy_event_to_schema_table(THD *thd, TABLE *sch_table, TABLE *event_table)
|
|||||||
*/
|
*/
|
||||||
if (thd->lex->sql_command != SQLCOM_SHOW_EVENTS &&
|
if (thd->lex->sql_command != SQLCOM_SHOW_EVENTS &&
|
||||||
check_access(thd, EVENT_ACL, et.dbname.str, 0, 0, 1,
|
check_access(thd, EVENT_ACL, et.dbname.str, 0, 0, 1,
|
||||||
is_schema_db(et.dbname.str)))
|
is_schema_db(et.dbname.str, et.dbname.length)))
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
|
|
||||||
/* ->field[0] is EVENT_CATALOG and is by default NULL */
|
/* ->field[0] is EVENT_CATALOG and is by default NULL */
|
||||||
|
@ -268,11 +268,11 @@ bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
|
|||||||
table (i.e. user will not get some privileges by view creation)
|
table (i.e. user will not get some privileges by view creation)
|
||||||
*/
|
*/
|
||||||
if ((check_access(thd, CREATE_VIEW_ACL, view->db, &view->grant.privilege,
|
if ((check_access(thd, CREATE_VIEW_ACL, view->db, &view->grant.privilege,
|
||||||
0, 0, is_schema_db(view->db)) ||
|
0, 0, is_schema_db(view->db, view->db_length)) ||
|
||||||
check_grant(thd, CREATE_VIEW_ACL, view, 0, 1, 0)) ||
|
check_grant(thd, CREATE_VIEW_ACL, view, 0, 1, 0)) ||
|
||||||
(mode != VIEW_CREATE_NEW &&
|
(mode != VIEW_CREATE_NEW &&
|
||||||
(check_access(thd, DROP_ACL, view->db, &view->grant.privilege,
|
(check_access(thd, DROP_ACL, view->db, &view->grant.privilege,
|
||||||
0, 0, is_schema_db(view->db)) ||
|
0, 0, is_schema_db(view->db, view->db_length)) ||
|
||||||
check_grant(thd, DROP_ACL, view, 0, 1, 0))))
|
check_grant(thd, DROP_ACL, view, 0, 1, 0))))
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
@ -212,10 +212,7 @@ TABLE_CATEGORY get_table_category(const LEX_STRING *db, const LEX_STRING *name)
|
|||||||
DBUG_ASSERT(db != NULL);
|
DBUG_ASSERT(db != NULL);
|
||||||
DBUG_ASSERT(name != NULL);
|
DBUG_ASSERT(name != NULL);
|
||||||
|
|
||||||
if ((db->length == INFORMATION_SCHEMA_NAME.length) &&
|
if (is_schema_db(db->str, db->length))
|
||||||
(my_strcasecmp(system_charset_info,
|
|
||||||
INFORMATION_SCHEMA_NAME.str,
|
|
||||||
db->str) == 0))
|
|
||||||
{
|
{
|
||||||
return TABLE_CATEGORY_INFORMATION;
|
return TABLE_CATEGORY_INFORMATION;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user