diff options
author | Sergei Golubchik <serg@mariadb.org> | 2017-03-02 20:59:29 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2017-03-10 18:21:23 +0100 |
commit | 8eb66bc382295003e5da5ff50365d62def30f52d (patch) | |
tree | ba58e522d6e2a0e0e2629c74160d4c8ef2e50f6d /sql | |
parent | 1c8d2121ab0e9ca0d8a8fccdd85da1072ef30815 (diff) | |
download | mariadb-git-8eb66bc382295003e5da5ff50365d62def30f52d.tar.gz |
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.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/datadict.cc | 50 | ||||
-rw-r--r-- | sql/datadict.h | 5 | ||||
-rw-r--r-- | sql/handler.cc | 14 | ||||
-rw-r--r-- | sql/sql_plugin.cc | 7 |
4 files changed, 41 insertions, 35 deletions
diff --git a/sql/datadict.cc b/sql/datadict.cc index 287e8568d90..ee0d8805f95 100644 --- a/sql/datadict.cc +++ b/sql/datadict.cc @@ -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. - @param[in] thd The current session. - @param[in] path path to FRM file. - @param[out] dbt db_type of the table if FRMTYPE_TABLE, otherwise undefined. + @param[in] thd The current session. + @param[in] path path to FRM file. + @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_TABLE table @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; uchar header[10]; //"TYPE=VIEW\n" it is 10 characters size_t error; frm_type_enum type= FRMTYPE_ERROR; + uchar dbt; 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) DBUG_RETURN(FRMTYPE_ERROR); 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; - /* - 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)) + if (!is_binary_frm_header(header) || !engine_name) goto err; - *dbt= (enum legacy_db_type) (uint) *(header + 3); + engine_name->length= 0; + dbt= header[3]; + + /* 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; + } + } - if (*dbt >= DB_TYPE_FIRST_DYNAMIC) /* read the true engine name */ + /* read the true engine name */ { MY_STAT state; 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; if (next_chunk + 2 < buff_end) { - uint str_db_type_length= uint2korr(next_chunk); - LEX_STRING name; - name.str= (char*) next_chunk + 2; - name.length= str_db_type_length; - 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; + uint len= uint2korr(next_chunk); + if (len <= NAME_CHAR_LEN) + strmake(engine_name->str, (char*)next_chunk + 2, + engine_name->length= len); } } diff --git a/sql/datadict.h b/sql/datadict.h index dd80942daca..9b180a882f9 100644 --- a/sql/datadict.h +++ b/sql/datadict.h @@ -35,12 +35,11 @@ enum frm_type_enum Prefer to use ha_table_exists() instead. 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) { - enum legacy_db_type not_used; - return dd_frm_type(thd, path, ¬_used) == FRMTYPE_VIEW; + return dd_frm_type(thd, path, NULL) == FRMTYPE_VIEW; } bool dd_recreate_table(THD *thd, const char *db, const char *table_name, diff --git a/sql/handler.cc b/sql/handler.cc index 751b6d3ca3c..17d00ce2486 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5025,14 +5025,16 @@ bool ha_table_exists(THD *thd, const char *db, const char *table_name, bool exists= true; if (hton) { - enum legacy_db_type db_type; - if (dd_frm_type(thd, path, &db_type) != FRMTYPE_VIEW) + char engine_buf[NAME_CHAR_LEN + 1]; + 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); - if ((*hton= ht)) + 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, - plugin_int_to_ref(hton2plugin[ht->slot]), &args); + exists= discover_existence(thd, p, &args); } else *hton= view_pseudo_hton; diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index ed0721feb3b..4ba9b82cf47 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1646,10 +1646,11 @@ 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); - enum legacy_db_type db_type; - frm_type_enum frm_type= dd_frm_type(NULL, path, &db_type); + char engine_name_buf[NAME_CHAR_LEN + 1]; + 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 (frm_type == FRMTYPE_TABLE && db_type == DB_TYPE_MYISAM) + if (frm_type == FRMTYPE_TABLE && !strcasecmp(maybe_myisam.str, "MyISAM")) { plugin_load(&tmp_root); flags|= PLUGIN_INIT_SKIP_PLUGIN_TABLE; |