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
|
If engine_name is 0, then the function will only test if the file is a
|
||||||
view or not
|
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_UNKNOWN error - file can't be opened
|
||||||
@retval TABLE_TYPE_NORMAL table
|
@retval TABLE_TYPE_NORMAL table
|
||||||
@retval TABLE_TYPE_SEQUENCE sequence table
|
@retval TABLE_TYPE_SEQUENCE sequence table
|
||||||
@retval TABLE_TYPE_VIEW view
|
@retval TABLE_TYPE_VIEW view
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name,
|
Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name)
|
||||||
bool *is_sequence)
|
|
||||||
{
|
{
|
||||||
File file;
|
File file;
|
||||||
uchar header[40]; //"TYPE=VIEW\n" it is 10 characters
|
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;
|
uchar dbt;
|
||||||
DBUG_ENTER("dd_frm_type");
|
DBUG_ENTER("dd_frm_type");
|
||||||
|
|
||||||
*is_sequence= 0;
|
file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0));
|
||||||
|
if (file < 0)
|
||||||
if ((file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0)))
|
|
||||||
< 0)
|
|
||||||
DBUG_RETURN(TABLE_TYPE_UNKNOWN);
|
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)
|
if (((header[39] >> 4) & 3) == HA_CHOICE_YES)
|
||||||
{
|
{
|
||||||
DBUG_PRINT("info", ("Sequence found"));
|
DBUG_PRINT("info", ("Sequence found"));
|
||||||
*is_sequence= 1;
|
type= TABLE_TYPE_SEQUENCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* cannot use ha_resolve_by_legacy_type without a THD */
|
/* 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().
|
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,
|
enum Table_type dd_frm_type(THD *thd, char *path, LEX_CSTRING *engine_name);
|
||||||
bool *is_sequence);
|
|
||||||
|
|
||||||
static inline bool dd_frm_is_view(THD *thd, char *path)
|
static inline bool dd_frm_is_view(THD *thd, char *path)
|
||||||
{
|
{
|
||||||
bool not_used2;
|
return dd_frm_type(thd, path, NULL) == TABLE_TYPE_VIEW;
|
||||||
return dd_frm_type(thd, path, NULL, ¬_used2) == TABLE_TYPE_VIEW;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dd_recreate_table(THD *thd, const char *db, const char *table_name);
|
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];
|
char engine_buf[NAME_CHAR_LEN + 1];
|
||||||
LEX_CSTRING engine= { engine_buf, 0 };
|
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)) ==
|
switch (type) {
|
||||||
TABLE_TYPE_UNKNOWN)
|
case TABLE_TYPE_UNKNOWN:
|
||||||
{
|
DBUG_PRINT("exit", ("Exist, cannot be opened"));
|
||||||
DBUG_PRINT("exit", ("Does not exist"));
|
|
||||||
DBUG_RETURN(true); // Frm exists
|
DBUG_RETURN(true); // Frm exists
|
||||||
}
|
case TABLE_TYPE_VIEW:
|
||||||
if (type != TABLE_TYPE_VIEW)
|
*hton= view_pseudo_hton;
|
||||||
{
|
DBUG_PRINT("exit", ("Exist, view"));
|
||||||
plugin_ref p= plugin_lock_by_name(thd, &engine,
|
DBUG_RETURN(true); // Frm exists
|
||||||
MYSQL_STORAGE_ENGINE_PLUGIN);
|
case TABLE_TYPE_SEQUENCE:
|
||||||
*hton= p ? plugin_hton(p) : NULL;
|
*is_sequence= true;
|
||||||
if (*hton)
|
/* fall through */
|
||||||
|
case TABLE_TYPE_NORMAL:
|
||||||
{
|
{
|
||||||
// verify that the table really exists
|
plugin_ref p= plugin_lock_by_name(thd, &engine,
|
||||||
exists= discover_existence(thd, p, &args);
|
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_PRINT("exit", (exists ? "Exists" : "Does not exist"));
|
||||||
DBUG_RETURN(exists);
|
DBUG_RETURN(exists);
|
||||||
|
@ -1720,8 +1720,7 @@ int plugin_init(int *argc, char **argv, int flags)
|
|||||||
{
|
{
|
||||||
char path[FN_REFLEN + 1];
|
char path[FN_REFLEN + 1];
|
||||||
build_table_filename(path, sizeof(path) - 1, "mysql", "plugin", reg_ext, 0);
|
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);
|
||||||
Table_type ttype= dd_frm_type(0, path, &plugin_table_engine_name, &dummy);
|
|
||||||
if (ttype != TABLE_TYPE_NORMAL)
|
if (ttype != TABLE_TYPE_NORMAL)
|
||||||
plugin_table_engine_name=empty_clex_str;
|
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];
|
char path[FN_REFLEN];
|
||||||
build_table_filename(path, sizeof(path) - 1,
|
build_table_filename(path, sizeof(path) - 1,
|
||||||
db->str, table->str, reg_ext, 0);
|
db->str, table->str, reg_ext, 0);
|
||||||
bool is_sequence;
|
if (dd_frm_type(thd, path, &engine_name) == TABLE_TYPE_NORMAL)
|
||||||
if (dd_frm_type(thd, path, &engine_name, &is_sequence) == TABLE_TYPE_NORMAL)
|
|
||||||
tl->option= engine_name.str;
|
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];
|
char eng_type_buf[NAME_CHAR_LEN+1];
|
||||||
LEX_CSTRING eng_type_str = {eng_type_buf, 0};
|
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);
|
||||||
enum Table_type type = dd_frm_type(nullptr, fullfilename.c_ptr(), &eng_type_str, &is_sequence);
|
|
||||||
if (type == TABLE_TYPE_UNKNOWN) {
|
if (type == TABLE_TYPE_UNKNOWN) {
|
||||||
// NO_LINT_DEBUG
|
// NO_LINT_DEBUG
|
||||||
sql_print_warning("RocksDB: Failed to open/read .from file: %s",
|
sql_print_warning("RocksDB: Failed to open/read .from file: %s",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user