summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2020-06-15 14:06:08 +0200
committerSergei Golubchik <serg@mariadb.org>2020-07-04 01:44:46 +0200
commit35f566db8d847c707d0ba7f3de239bfeee9ca845 (patch)
treeb3089bb0b9185ac60c00a3a2b1eb8ba2e02f3721
parent2bb5981c202f85c8399485d6a57a69d8c6f627af (diff)
downloadmariadb-git-35f566db8d847c707d0ba7f3de239bfeee9ca845.tar.gz
cleanup: make dd_frm_type to work as documented
remove redundant argument, return all possible enum values
-rw-r--r--sql/datadict.cc13
-rw-r--r--sql/datadict.h6
-rw-r--r--sql/handler.cc33
-rw-r--r--sql/sql_plugin.cc3
-rw-r--r--sql/sql_show.cc3
-rw-r--r--storage/rocksdb/rdb_datadic.cc3
6 files changed, 26 insertions, 35 deletions
diff --git a/sql/datadict.cc b/sql/datadict.cc
index 5cfda166b2b..e09eee98565 100644
--- a/sql/datadict.cc
+++ b/sql/datadict.cc
@@ -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 */
diff --git a/sql/datadict.h b/sql/datadict.h
index cbdf788deb6..f4af592247a 100644
--- a/sql/datadict.h
+++ b/sql/datadict.h
@@ -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, &not_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);
diff --git a/sql/handler.cc b/sql/handler.cc
index 28588235477..d81684f7c5f 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -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);
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 4750be99d30..4526cac5af1 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -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;
}
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 5eb2d911926..64076197cf8 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -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;
}
}
diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc
index 6e73535d1de..13da87ad92c 100644
--- a/storage/rocksdb/rdb_datadic.cc
+++ b/storage/rocksdb/rdb_datadic.cc
@@ -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",