From f6b1922c313ce1a1cb81b8e84f8f34ecab1ec304 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 22 Apr 2017 02:04:49 +0200 Subject: fixes for mysql 5.7 --- configure.ac | 15 ------ m4/ac_mysql.m4 | 2 +- src/table_sizes.cc | 133 ++++++++++++++++++++++++++++++----------------------- 3 files changed, 76 insertions(+), 74 deletions(-) diff --git a/configure.ac b/configure.ac index 5e655dc..48857f8 100644 --- a/configure.ac +++ b/configure.ac @@ -27,26 +27,11 @@ AC_DEFUN([CHECK_DEBUG], [ ) ]) -AC_DEFUN([CHECK_FAST_MUTEXES], [ - AC_ARG_ENABLE([fast-mutexes], - AS_HELP_STRING([--enable-fast-mutexes], [compile with fast mutexes, default: no])) - - AC_MSG_CHECKING(whether to compile with fast mutexes) - AS_IF([test "x$enable_fast_mutexes" = "xyes"], - [ - CPPFLAGS="$CPPFLAGS -DMY_PTHREAD_FASTMUTEX=1" - AC_MSG_RESULT(yes) - ], - [ AC_MSG_RESULT(no) ] - ) -]) - dnl Run tests using C++ compiler dnl AC_LANG(C++) CHECK_DEBUG -CHECK_FAST_MUTEXES #check for mysql src MYSQL_SRC_TEST diff --git a/m4/ac_mysql.m4 b/m4/ac_mysql.m4 index ef23f9e..b5a5c0c 100644 --- a/m4/ac_mysql.m4 +++ b/m4/ac_mysql.m4 @@ -30,7 +30,7 @@ AC_DEFUN([MYSQL_SRC_TEST], [ fi done AC_DEFINE([MYSQL_SRC], [1], [Source directory for MySQL]) - MYSQL_INC="-I$ac_mysql_source_dir/sql -I$ac_mysql_source_dir/include -I$ac_mysql_source_dir/regex -I$ac_mysql_source_dir" + MYSQL_INC="-I$ac_mysql_source_dir/sql -I$ac_mysql_source_dir/include -I$ac_mysql_source_dir/regex -I$ac_mysql_source_dir -I$ac_mysql_source_dir/libbinlogevents/export -I$ac_mysql_source_dir/libbinlogevents/include -I$ac_mysql_source_dir/sql/auth" AC_MSG_RESULT(["$ac_mysql_source_dir"]) ], [ diff --git a/src/table_sizes.cc b/src/table_sizes.cc index 2b13b6f..b1b38bb 100644 --- a/src/table_sizes.cc +++ b/src/table_sizes.cc @@ -13,10 +13,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mysql_inc.h" +#include #include #include #include #include +#include #define STR_OR_NIL(S) ((S) ? (S) : "") @@ -26,7 +28,7 @@ typedef struct st_lookup_field_values bool wild_db_value, wild_table_value; } LOOKUP_FIELD_VALUES; -bool calc_lookup_values_from_cond(THD *thd, Item *cond, TABLE_LIST *table, +bool get_lookup_field_values(THD *thd, Item *cond, TABLE_LIST *table, LOOKUP_FIELD_VALUES *lookup_field_vals); /*----------------------------------------------------------------------------*/ @@ -37,13 +39,13 @@ make_db_list(THD *thd, List *db_names, MEM_ROOT *tmp_mem_root) { /* - If we have db lookup vaule we just add it to list and + If we have db lookup value we just add it to list and exit from the function. We don't do this for database names longer than the maximum path length. */ if (lookup_field_vals->db_value.str - && lookup_field_vals->db_value.length < FN_REFLEN) + && lookup_field_vals->db_value.length <= NAME_LEN) { if (db_names->push_back(&lookup_field_vals->db_value)) return 1; @@ -62,14 +64,6 @@ struct TABLE_DATA longlong size; }; -static char *fn_remove_ext(char *name) -{ - char *res = strrchr(name, '.'); - if (res) - return res; - return name + strlen(name); -} - /* SYNOPSIS thd thread handler @@ -84,35 +78,56 @@ static char *fn_remove_ext(char *name) FIND_FILES_DIR no such directory, or directory can't be read */ static find_files_result -find_tables(THD *thd, List *tables, - const char *db, const char *path, const char *wild) +find_tables(THD *thd, List *tables, const char *db, + const char *path, const char *wild, MEM_ROOT *tmp_mem_root) { - char *ext; MY_DIR *dirp; - FILEINFO *file; - uint file_name_len; - char uname[NAME_LEN + 1]; /* Unencoded name */ + MEM_ROOT **root_ptr = NULL, *old_root = NULL; #ifndef NO_EMBEDDED_ACCESS_CHECKS uint col_access = thd->col_access; #endif - uint wild_length = 0; + size_t wild_length = 0; TABLE_LIST table_list; TABLE_DATA *table_data = NULL; DBUG_ENTER("find_files"); + if (wild) + { + if (!wild[0]) + wild = 0; + else + wild_length = strlen(wild); + } + memset(&table_list, 0, sizeof(table_list)); if (!(dirp = my_dir(path, MYF(MY_WANT_STAT)))) { - if (my_errno == ENOENT) - my_error(ER_BAD_DB_ERROR, MYF(ME_BELL + ME_WAITTANG), db); + if (my_errno() == ENOENT) + my_error(ER_BAD_DB_ERROR, MYF(0), db); else - my_error(ER_CANT_READ_DIR, MYF(ME_BELL + ME_WAITTANG), path, my_errno); + { + char errbuf[MYSYS_STRERROR_SIZE]; + my_error(ER_CANT_READ_DIR, MYF(0), path, + my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno())); + } DBUG_RETURN(FIND_FILES_DIR); } - for (uint i = 0; i < (uint)dirp->number_off_files; i++) + if (tmp_mem_root) + { + root_ptr = my_thread_get_THR_MALLOC(); + old_root = *root_ptr; + *root_ptr = tmp_mem_root; + } + + for (uint i = 0; i < dirp->number_off_files; i++) { + char uname[NAME_LEN + 1]; /* Unencoded name */ + FILEINFO *file; + size_t file_name_len; + char *ext; + file = dirp->dir_entry + i; /* skip '.', '..', db.opt and temp files. */ if ((file->name[0] == '.' && @@ -121,15 +136,19 @@ find_tables(THD *thd, List *tables, || is_prefix(file->name, tmp_file_prefix)) continue; - ext = fn_remove_ext(file->name); - *ext = 0; + if ((ext = strrchr(file->name, '.'))) + *ext = 0; file_name_len = filename_to_tablename(file->name, uname, sizeof(uname)); - if (table_data != NULL - && !my_strcasecmp(files_charset_info, uname, table_data->name.str)) + if (table_data != NULL) { - table_data->size += file->mystat->st_size; - continue; + if (!my_strcasecmp(files_charset_info, uname, table_data->name.str)) + { + table_data->size += file->mystat->st_size; + continue; + } + else + table_data = NULL; } if (wild) @@ -150,7 +169,7 @@ find_tables(THD *thd, List *tables, /* Don't show tables where we don't have any privileges */ if (db && !(col_access & TABLE_ACLS)) { - table_list.db = (char*)db; + table_list.db = db; table_list.db_length = strlen(db); table_list.table_name = uname; table_list.table_name_length = file_name_len; @@ -162,7 +181,11 @@ find_tables(THD *thd, List *tables, table_data = new TABLE_DATA(); table_data->size = file->mystat->st_size; - if (!thd->make_lex_string(&table_data->name, uname, file_name_len, FALSE) + if (!(tmp_mem_root + ? make_lex_string_root(tmp_mem_root, &table_data->name, uname, + file_name_len, FALSE) + : thd->make_lex_string(&table_data->name, uname, + file_name_len, FALSE)) || tables->push_back(table_data)) { my_dirend(dirp); @@ -175,23 +198,28 @@ find_tables(THD *thd, List *tables, //(void)ha_find_files(thd, db, path, wild, dir, files); + if (tmp_mem_root) + *root_ptr = old_root; + DBUG_RETURN(FIND_FILES_OK); } static int make_table_list(THD *thd, List *table_names, LEX *lex, - LEX_STRING *db_name) + LOOKUP_FIELD_VALUES *lookup_field_vals, LEX_STRING *db_name, + MEM_ROOT *tmp_mem_root) { char path[FN_REFLEN + 1]; build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0); find_files_result res = find_tables(thd, table_names, db_name->str, path, - NullS); + lookup_field_vals->table_value.str, tmp_mem_root); if (res != FIND_FILES_OK) { /* - Downgrade errors about problems with database directory to warnings. - Another thread may have dropped database, and we may still have a name + Downgrade errors about problems with database directory to + warnings if this is not a 'SHOW' command. Another thread + may have dropped database, and we may still have a name for that directory. */ if (res == FIND_FILES_DIR) @@ -217,7 +245,7 @@ static ST_FIELD_INFO fields_info[] = {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name", SKIP_OPEN_TABLE}, {"TABLE_SIZE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, - (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Table_size", SKIP_OPEN_TABLE}, + MY_I_S_UNSIGNED, "Table_size", SKIP_OPEN_TABLE}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} }; @@ -227,7 +255,7 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond) TABLE *table = tables->table; LOOKUP_FIELD_VALUES lookup_field_vals; #ifndef NO_EMBEDDED_ACCESS_CHECKS - Security_context *sctx = thd->security_ctx; + Security_context *sctx = thd->security_context(); #endif List db_names; List_iterator_fast it(db_names); @@ -236,27 +264,15 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond) DBUG_ENTER("fill_table"); MEM_ROOT tmp_mem_root; - init_sql_alloc(&tmp_mem_root, TABLE_ALLOC_BLOCK_SIZE, 0); + init_sql_alloc(key_memory_get_all_tables, &tmp_mem_root, + TABLE_ALLOC_BLOCK_SIZE, 0); - memset(&lookup_field_vals, 0, sizeof(LOOKUP_FIELD_VALUES)); - if (calc_lookup_values_from_cond(thd, cond, tables, &lookup_field_vals)) + if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals)) { error = 0; goto err; } - if (lower_case_table_names) - { - /* - We can safely do in-place upgrades here since we are - allocating a new memory buffer for these strings. - */ - if (lookup_field_vals.db_value.str && lookup_field_vals.db_value.str[0]) - my_casedn_str(system_charset_info, lookup_field_vals.db_value.str); - if (lookup_field_vals.table_value.str && lookup_field_vals.table_value.str[0]) - my_casedn_str(system_charset_info, lookup_field_vals.table_value.str); - } - DBUG_PRINT("INDEX VALUES", ("db_name='%s', table_name='%s'", STR_OR_NIL(lookup_field_vals.db_value.str), STR_OR_NIL(lookup_field_vals.table_value.str))); @@ -296,19 +312,21 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond) goto err; LEX_STRING *db_name; + it.rewind(); /* To get access to new elements in basis list */ while ((db_name = it++)) { #ifndef NO_EMBEDDED_ACCESS_CHECKS if ((check_access(thd, SELECT_ACL, db_name->str, &thd->col_access, NULL, 0, 1) || (!thd->col_access && check_grant_db(thd, db_name->str))) - && !sctx->master_access & (DB_ACLS | SHOW_DB_ACL) - && !acl_get(sctx->get_host()->ptr(), sctx->get_ip()->ptr(), - sctx->priv_user, db_name->str, 0)) + && !sctx->check_access(DB_ACLS | SHOW_DB_ACL, true) + && !acl_get(sctx->host().str, sctx->ip().str, + sctx->priv_user().str, db_name->str, 0)) continue; #endif List tables; - int res = make_table_list(thd, &tables, lex, db_name); + int res = make_table_list(thd, &tables, lex, &lookup_field_vals, + db_name, &tmp_mem_root); if (res) { tables.delete_elements(); @@ -325,8 +343,7 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond) system_charset_info); table->field[1]->store(table_data->name.str, table_data->name.length, system_charset_info); - table->field[2]->set_notnull(); - table->field[2]->store((longlong) table_data->size, TRUE); + table->field[2]->store(table_data->size, TRUE); if (schema_table_store_record(thd, table)) { tables.delete_elements(); @@ -367,7 +384,7 @@ mysql_declare_plugin(table_sizes) PLUGIN_LICENSE_GPL, /* license type */ init, /* init function */ NULL, - 0x0506, /* version = 5.6 */ + 0x0507, /* version = 5.7 */ NULL, /* no status variables */ NULL, /* no system variables */ NULL, /* no reserved information */ -- cgit v1.2.3