mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
cleanup: change dd_frm_type() to return the engine name, not legacy_db_type
this simplifies the code and avoids unnecessary conversions back and forth. and it works even if the engine is not installed.
This commit is contained in:
@ -39,25 +39,27 @@ static int read_string(File file, uchar**to, size_t length)
|
|||||||
/**
|
/**
|
||||||
Check type of .frm if we are not going to parse it.
|
Check type of .frm if we are not going to parse it.
|
||||||
|
|
||||||
@param[in] thd The current session.
|
@param[in] thd The current session.
|
||||||
@param[in] path path to FRM file.
|
@param[in] path path to FRM file.
|
||||||
@param[out] dbt db_type of the table if FRMTYPE_TABLE, otherwise undefined.
|
@param[in/out] engine_name table engine name (length < NAME_CHAR_LEN)
|
||||||
|
|
||||||
|
engine_name is a LEX_STRING, where engine_name->str must point to
|
||||||
|
a buffer of at least NAME_CHAR_LEN+1 bytes.
|
||||||
|
|
||||||
@retval FRMTYPE_ERROR error
|
@retval FRMTYPE_ERROR error
|
||||||
@retval FRMTYPE_TABLE table
|
@retval FRMTYPE_TABLE table
|
||||||
@retval FRMTYPE_VIEW view
|
@retval FRMTYPE_VIEW view
|
||||||
*/
|
*/
|
||||||
|
|
||||||
frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
|
frm_type_enum dd_frm_type(THD *thd, char *path, LEX_STRING *engine_name)
|
||||||
{
|
{
|
||||||
File file;
|
File file;
|
||||||
uchar header[10]; //"TYPE=VIEW\n" it is 10 characters
|
uchar header[10]; //"TYPE=VIEW\n" it is 10 characters
|
||||||
size_t error;
|
size_t error;
|
||||||
frm_type_enum type= FRMTYPE_ERROR;
|
frm_type_enum type= FRMTYPE_ERROR;
|
||||||
|
uchar dbt;
|
||||||
DBUG_ENTER("dd_frm_type");
|
DBUG_ENTER("dd_frm_type");
|
||||||
|
|
||||||
*dbt= DB_TYPE_UNKNOWN;
|
|
||||||
|
|
||||||
if ((file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0))) < 0)
|
if ((file= mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0))) < 0)
|
||||||
DBUG_RETURN(FRMTYPE_ERROR);
|
DBUG_RETURN(FRMTYPE_ERROR);
|
||||||
error= mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP));
|
error= mysql_file_read(file, (uchar*) header, sizeof(header), MYF(MY_NABP));
|
||||||
@ -72,17 +74,24 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
|
|||||||
|
|
||||||
type= FRMTYPE_TABLE;
|
type= FRMTYPE_TABLE;
|
||||||
|
|
||||||
/*
|
if (!is_binary_frm_header(header) || !engine_name)
|
||||||
This is just a check for DB_TYPE. We'll return default unknown type
|
|
||||||
if the following test is true (arg #3). This should not have effect
|
|
||||||
on return value from this function (default FRMTYPE_TABLE)
|
|
||||||
*/
|
|
||||||
if (!is_binary_frm_header(header))
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
*dbt= (enum legacy_db_type) (uint) *(header + 3);
|
engine_name->length= 0;
|
||||||
|
dbt= header[3];
|
||||||
|
|
||||||
if (*dbt >= DB_TYPE_FIRST_DYNAMIC) /* read the true engine name */
|
/* cannot use ha_resolve_by_legacy_type without a THD */
|
||||||
|
if (thd && dbt < DB_TYPE_FIRST_DYNAMIC)
|
||||||
|
{
|
||||||
|
handlerton *ht= ha_resolve_by_legacy_type(thd, (enum legacy_db_type)dbt);
|
||||||
|
if (ht)
|
||||||
|
{
|
||||||
|
*engine_name= hton2plugin[ht->slot]->name;
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read the true engine name */
|
||||||
{
|
{
|
||||||
MY_STAT state;
|
MY_STAT state;
|
||||||
uchar *frm_image= 0;
|
uchar *frm_image= 0;
|
||||||
@ -110,15 +119,10 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
|
|||||||
next_chunk+= connect_string_length + 2;
|
next_chunk+= connect_string_length + 2;
|
||||||
if (next_chunk + 2 < buff_end)
|
if (next_chunk + 2 < buff_end)
|
||||||
{
|
{
|
||||||
uint str_db_type_length= uint2korr(next_chunk);
|
uint len= uint2korr(next_chunk);
|
||||||
LEX_STRING name;
|
if (len <= NAME_CHAR_LEN)
|
||||||
name.str= (char*) next_chunk + 2;
|
strmake(engine_name->str, (char*)next_chunk + 2,
|
||||||
name.length= str_db_type_length;
|
engine_name->length= len);
|
||||||
plugin_ref tmp_plugin= ha_resolve_by_name(thd, &name, false);
|
|
||||||
if (tmp_plugin)
|
|
||||||
*dbt= plugin_data(tmp_plugin, handlerton *)->db_type;
|
|
||||||
else
|
|
||||||
*dbt= DB_TYPE_UNKNOWN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,12 +35,11 @@ enum frm_type_enum
|
|||||||
Prefer to use ha_table_exists() instead.
|
Prefer to use ha_table_exists() instead.
|
||||||
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().
|
||||||
*/
|
*/
|
||||||
frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt);
|
frm_type_enum dd_frm_type(THD *thd, char *path, LEX_STRING *engine_name);
|
||||||
|
|
||||||
static inline bool dd_frm_is_view(THD *thd, char *path)
|
static inline bool dd_frm_is_view(THD *thd, char *path)
|
||||||
{
|
{
|
||||||
enum legacy_db_type not_used;
|
return dd_frm_type(thd, path, NULL) == FRMTYPE_VIEW;
|
||||||
return dd_frm_type(thd, path, ¬_used) == FRMTYPE_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,
|
||||||
|
@ -5025,14 +5025,16 @@ bool ha_table_exists(THD *thd, const char *db, const char *table_name,
|
|||||||
bool exists= true;
|
bool exists= true;
|
||||||
if (hton)
|
if (hton)
|
||||||
{
|
{
|
||||||
enum legacy_db_type db_type;
|
char engine_buf[NAME_CHAR_LEN + 1];
|
||||||
if (dd_frm_type(thd, path, &db_type) != FRMTYPE_VIEW)
|
LEX_STRING engine= { engine_buf, 0 };
|
||||||
|
|
||||||
|
if (dd_frm_type(thd, path, &engine) != FRMTYPE_VIEW)
|
||||||
{
|
{
|
||||||
handlerton *ht= ha_resolve_by_legacy_type(thd, db_type);
|
plugin_ref p= plugin_lock_by_name(thd, &engine, MYSQL_STORAGE_ENGINE_PLUGIN);
|
||||||
if ((*hton= ht))
|
*hton= p ? plugin_hton(p) : NULL;
|
||||||
|
if (*hton)
|
||||||
// verify that the table really exists
|
// verify that the table really exists
|
||||||
exists= discover_existence(thd,
|
exists= discover_existence(thd, p, &args);
|
||||||
plugin_int_to_ref(hton2plugin[ht->slot]), &args);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*hton= view_pseudo_hton;
|
*hton= view_pseudo_hton;
|
||||||
|
@ -1646,10 +1646,11 @@ 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);
|
||||||
enum legacy_db_type db_type;
|
char engine_name_buf[NAME_CHAR_LEN + 1];
|
||||||
frm_type_enum frm_type= dd_frm_type(NULL, path, &db_type);
|
LEX_STRING maybe_myisam= { engine_name_buf, 0 };
|
||||||
|
frm_type_enum frm_type= dd_frm_type(NULL, path, &maybe_myisam);
|
||||||
/* if mysql.plugin table is MyISAM - load it right away */
|
/* if mysql.plugin table is MyISAM - load it right away */
|
||||||
if (frm_type == FRMTYPE_TABLE && db_type == DB_TYPE_MYISAM)
|
if (frm_type == FRMTYPE_TABLE && !strcasecmp(maybe_myisam.str, "MyISAM"))
|
||||||
{
|
{
|
||||||
plugin_load(&tmp_root);
|
plugin_load(&tmp_root);
|
||||||
flags|= PLUGIN_INIT_SKIP_PLUGIN_TABLE;
|
flags|= PLUGIN_INIT_SKIP_PLUGIN_TABLE;
|
||||||
|
Reference in New Issue
Block a user