Skip to content

Commit

Permalink
MDEV-31986 Remove old check_db_name() from make_table_name_list()
Browse files Browse the repository at this point in the history
- Replacing the old style inplace check_db_name() in make_table_name_list()
  to the new style non-modifying code
- Adding "const" qualifier to the "db" parameter to ha_discover_table_names()
  and its dependency functions.
  • Loading branch information
abarkov committed Aug 23, 2023
1 parent d15e290 commit 21218d3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
7 changes: 4 additions & 3 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ static int full_discover_for_existence(handlerton *, const char *, const char *)
static int ext_based_existence(handlerton *, const char *, const char *)
{ return 0; }

static int hton_ext_based_table_discovery(handlerton *hton, LEX_CSTRING *db,
static int hton_ext_based_table_discovery(handlerton *hton,
const LEX_CSTRING *db,
MY_DIR *dir, handlerton::discovered_list *result)
{
/*
Expand Down Expand Up @@ -6679,7 +6680,7 @@ void Discovered_table_list::remove_duplicates()

struct st_discover_names_args
{
LEX_CSTRING *db;
const LEX_CSTRING *db;
MY_DIR *dirp;
Discovered_table_list *result;
uint possible_duplicates;
Expand Down Expand Up @@ -6724,7 +6725,7 @@ static my_bool discover_names(THD *thd, plugin_ref plugin,
for DROP DATABASE (as it needs to know and delete non-table files).
*/

int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp,
int ha_discover_table_names(THD *thd, const LEX_CSTRING *db, MY_DIR *dirp,
Discovered_table_list *result, bool reusable)
{
int error;
Expand Down
5 changes: 3 additions & 2 deletions sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,8 @@ struct handlerton
Returns 0 on success and 1 on error.
*/
int (*discover_table_names)(handlerton *hton, LEX_CSTRING *db, MY_DIR *dir,
int (*discover_table_names)(handlerton *hton, const LEX_CSTRING *db,
MY_DIR *dir,
discovered_list *result);

/*
Expand Down Expand Up @@ -5574,7 +5575,7 @@ class Discovered_table_list: public handlerton::discovered_list
};

int ha_discover_table(THD *thd, TABLE_SHARE *share);
int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp,
int ha_discover_table_names(THD *thd, const LEX_CSTRING *db, MY_DIR *dirp,
Discovered_table_list *result, bool reusable);
bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *table_name,
Expand Down
9 changes: 8 additions & 1 deletion sql/lex_ident.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,16 @@ class DBNameBuffer: public CharBuffer<SAFE_NAME_LEN + MY_CS_MBMAXLEN>
{
copy_casedn(&my_charset_utf8mb3_general_ci, db, casedn);
}
Lex_ident_db to_lex_ident_db() const
{
const LEX_CSTRING tmp= to_lex_cstring();
if (Lex_ident_fs(tmp).check_db_name())
return Lex_ident_db();
return Lex_ident_db(tmp.str, tmp.length);
}
Lex_ident_db to_lex_ident_db_with_error() const
{
LEX_CSTRING tmp= to_lex_cstring();
const LEX_CSTRING tmp= to_lex_cstring();
if (Lex_ident_fs(tmp).check_db_name_with_error())
return Lex_ident_db();
return Lex_ident_db(tmp.str, tmp.length);
Expand Down
11 changes: 7 additions & 4 deletions sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,8 @@ enum find_files_result {


static find_files_result
find_files(THD *thd, Dynamic_array<LEX_CSTRING*> *files, LEX_CSTRING *db,
find_files(THD *thd, Dynamic_array<LEX_CSTRING*> *files,
const Lex_ident_db *db,
const char *path, const LEX_CSTRING *wild)
{
MY_DIR *dirp;
Expand Down Expand Up @@ -4537,7 +4538,7 @@ int schema_tables_add(THD *thd, Dynamic_array<LEX_CSTRING*> *files,
static int
make_table_name_list(THD *thd, Dynamic_array<LEX_CSTRING*> *table_names,
LEX *lex, LOOKUP_FIELD_VALUES *lookup_field_vals,
LEX_CSTRING *db_name)
const LEX_CSTRING *db_name)
{
char path[FN_REFLEN + 1];
build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0);
Expand Down Expand Up @@ -4583,10 +4584,12 @@ make_table_name_list(THD *thd, Dynamic_array<LEX_CSTRING*> *table_names,
return (schema_tables_add(thd, table_names,
lookup_field_vals->table_value.str));

if (check_db_name((LEX_STRING*)db_name))
DBNameBuffer dbbuf(*db_name, lower_case_table_names);
const Lex_ident_db dbnorm= dbbuf.to_lex_ident_db();
if (!dbnorm.str)
return 0; // Impossible TABLE_SCHEMA name

find_files_result res= find_files(thd, table_names, db_name, path,
find_files_result res= find_files(thd, table_names, &dbnorm, path,
&lookup_field_vals->table_value);
if (res != FIND_FILES_OK)
{
Expand Down
2 changes: 1 addition & 1 deletion storage/maria/ha_s3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ static int s3_discover_table_existence(handlerton *hton, const char *db,
*/

static int s3_discover_table_names(handlerton *hton __attribute__((unused)),
LEX_CSTRING *db,
const LEX_CSTRING *db,
MY_DIR *dir __attribute__((unused)),
handlerton::discovered_list *result)
{
Expand Down
2 changes: 1 addition & 1 deletion storage/perfschema/pfs_engine_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,7 @@ bool pfs_show_status(handlerton *hton, THD *thd,
}

int pfs_discover_table_names(handlerton *hton __attribute__((unused)),
LEX_CSTRING *db,
const LEX_CSTRING *db,
MY_DIR *dir __attribute__((unused)),
handlerton::discovered_list *result)
{
Expand Down
2 changes: 1 addition & 1 deletion storage/perfschema/pfs_engine_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ struct PFS_triple_index
bool pfs_show_status(handlerton *hton, THD *thd,
stat_print_fn *print, enum ha_stat_type stat);

int pfs_discover_table_names(handlerton *hton, LEX_CSTRING *db,
int pfs_discover_table_names(handlerton *hton, const LEX_CSTRING *db,
MY_DIR *dir,
handlerton::discovered_list *result);

Expand Down

0 comments on commit 21218d3

Please sign in to comment.