cleanup: make dd_frm_type to work as documented
remove redundant argument, return all possible enum values
This commit is contained in:
parent
2bb5981c20
commit
35f566db8d
@ -49,16 +49,13 @@ static int read_string(File file, uchar**to, size_t length)
|
||||
If engine_name is 0, then the function will only test if the file is a
|
||||
view or not
|
||||
|
||||
@param[out] is_sequence 1 if table is a SEQUENCE, 0 otherwise
|
||||
|
||||
@retval TABLE_TYPE_UNKNOWN error - file can't be opened
|
||||
@retval TABLE_TYPE_NORMAL table
|
||||
@retval TABLE_TYPE_SEQUENCE sequence table
|
||||
@retval TABLE_TYPE_VIEW view
|
||||
*/
|
||||
|
||||
Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name,
|
||||
bool *is_sequence)
|
||||
Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name)
|
||||
{
|
||||
File file;
|
||||
uchar header[40]; //"TYPE=VIEW\n" it is 10 characters
|
||||
@ -67,10 +64,8 @@ Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name,
|
||||
uchar dbt;
|
||||
DBUG_ENTER("dd_frm_type");
|
||||
|
||||
*is_sequence= 0;
|
||||
|
||||
if ((file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0)))
|
||||
< 0)
|
||||
file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0));
|
||||
if (file < 0)
|
||||
DBUG_RETURN(TABLE_TYPE_UNKNOWN);
|
||||
|
||||
/*
|
||||
@ -110,7 +105,7 @@ Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name,
|
||||
if (((header[39] >> 4) & 3) == HA_CHOICE_YES)
|
||||
{
|
||||
DBUG_PRINT("info", ("Sequence found"));
|
||||
*is_sequence= 1;
|
||||
type= TABLE_TYPE_SEQUENCE;
|
||||
}
|
||||
|
||||
/* cannot use ha_resolve_by_legacy_type without a THD */
|
||||
|
@ -38,13 +38,11 @@ enum Table_type
|
||||
To check whether it's an frm of a view, use dd_frm_is_view().
|
||||
*/
|
||||
|
||||
enum Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name,
|
||||
bool *is_sequence);
|
||||
enum Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name);
|
||||
|
||||
static inline bool dd_frm_is_view(THD *thd, char *path)
|
||||
{
|
||||
bool not_used2;
|
||||
return dd_frm_type(thd, path, NULL, ¬_used2) == TABLE_TYPE_VIEW;
|
||||
return dd_frm_type(thd, path, NULL) == TABLE_TYPE_VIEW;
|
||||
}
|
||||
|
||||
bool dd_recreate_table(THD *thd, const char *db, const char *table_name);
|
||||
|
@ -5837,27 +5837,28 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
|
||||
{
|
||||
char engine_buf[NAME_CHAR_LEN + 1];
|
||||
LEX_CSTRING engine= { engine_buf, 0 };
|
||||
Table_type type;
|
||||
Table_type type= dd_frm_type(thd, path, &engine);
|
||||
|
||||
if ((type= dd_frm_type(thd, path, &engine, is_sequence)) ==
|
||||
TABLE_TYPE_UNKNOWN)
|
||||
{
|
||||
DBUG_PRINT("exit", ("Does not exist"));
|
||||
switch (type) {
|
||||
case TABLE_TYPE_UNKNOWN:
|
||||
DBUG_PRINT("exit", ("Exist, cannot be opened"));
|
||||
DBUG_RETURN(true); // Frm exists
|
||||
}
|
||||
if (type != TABLE_TYPE_VIEW)
|
||||
{
|
||||
plugin_ref p= plugin_lock_by_name(thd, &engine,
|
||||
MYSQL_STORAGE_ENGINE_PLUGIN);
|
||||
*hton= p ? plugin_hton(p) : NULL;
|
||||
if (*hton)
|
||||
case TABLE_TYPE_VIEW:
|
||||
*hton= view_pseudo_hton;
|
||||
DBUG_PRINT("exit", ("Exist, view"));
|
||||
DBUG_RETURN(true); // Frm exists
|
||||
case TABLE_TYPE_SEQUENCE:
|
||||
*is_sequence= true;
|
||||
/* fall through */
|
||||
case TABLE_TYPE_NORMAL:
|
||||
{
|
||||
// verify that the table really exists
|
||||
exists= discover_existence(thd, p, &args);
|
||||
plugin_ref p= plugin_lock_by_name(thd, &engine,
|
||||
MYSQL_STORAGE_ENGINE_PLUGIN);
|
||||
*hton= p ? plugin_hton(p) : NULL;
|
||||
if (*hton) // verify that the table really exists
|
||||
exists= discover_existence(thd, p, &args);
|
||||
}
|
||||
}
|
||||
else
|
||||
*hton= view_pseudo_hton;
|
||||
}
|
||||
DBUG_PRINT("exit", (exists ? "Exists" : "Does not exist"));
|
||||
DBUG_RETURN(exists);
|
||||
|
@ -1720,8 +1720,7 @@ int plugin_init(int *argc, char **argv, int flags)
|
||||
{
|
||||
char path[FN_REFLEN + 1];
|
||||
build_table_filename(path, sizeof(path) - 1, "mysql", "plugin", reg_ext, 0);
|
||||
bool dummy;
|
||||
Table_type ttype= dd_frm_type(0, path, &plugin_table_engine_name, &dummy);
|
||||
Table_type ttype= dd_frm_type(0, path, &plugin_table_engine_name);
|
||||
if (ttype != TABLE_TYPE_NORMAL)
|
||||
plugin_table_engine_name=empty_clex_str;
|
||||
}
|
||||
|
@ -4479,8 +4479,7 @@ static void get_table_engine_for_i_s(THD *thd, char *buf, TABLE_LIST *tl,
|
||||
char path[FN_REFLEN];
|
||||
build_table_filename(path, sizeof(path) - 1,
|
||||
db->str, table->str, reg_ext, 0);
|
||||
bool is_sequence;
|
||||
if (dd_frm_type(thd, path, &engine_name, &is_sequence) == TABLE_TYPE_NORMAL)
|
||||
if (dd_frm_type(thd, path, &engine_name) == TABLE_TYPE_NORMAL)
|
||||
tl->option= engine_name.str;
|
||||
}
|
||||
}
|
||||
|
@ -3793,8 +3793,7 @@ bool Rdb_validate_tbls::check_frm_file(const std::string &fullpath,
|
||||
*/
|
||||
char eng_type_buf[NAME_CHAR_LEN+1];
|
||||
LEX_CSTRING eng_type_str = {eng_type_buf, 0};
|
||||
bool is_sequence;
|
||||
enum Table_type type = dd_frm_type(nullptr, fullfilename.c_ptr(), &eng_type_str, &is_sequence);
|
||||
enum Table_type type = dd_frm_type(nullptr, fullfilename.c_ptr(), &eng_type_str);
|
||||
if (type == TABLE_TYPE_UNKNOWN) {
|
||||
// NO_LINT_DEBUG
|
||||
sql_print_warning("RocksDB: Failed to open/read .from file: %s",
|
||||
|
Loading…
x
Reference in New Issue
Block a user