summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2017-04-22 02:04:49 +0200
committermanuel <manuel@mausz.at>2017-04-22 02:04:49 +0200
commitf6b1922c313ce1a1cb81b8e84f8f34ecab1ec304 (patch)
treede0cf0743f1775cb28b82115fc95653d1579f26d
parent95c94b3758bb56457645eaafcd0cc7cb1515d374 (diff)
downloadmysql-table_sizes-f6b1922c313ce1a1cb81b8e84f8f34ecab1ec304.tar.gz
mysql-table_sizes-f6b1922c313ce1a1cb81b8e84f8f34ecab1ec304.tar.bz2
mysql-table_sizes-f6b1922c313ce1a1cb81b8e84f8f34ecab1ec304.zip
fixes for mysql 5.7v5.7
-rw-r--r--configure.ac15
-rw-r--r--m4/ac_mysql.m42
-rw-r--r--src/table_sizes.cc133
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], [
27 ) 27 )
28]) 28])
29 29
30AC_DEFUN([CHECK_FAST_MUTEXES], [
31 AC_ARG_ENABLE([fast-mutexes],
32 AS_HELP_STRING([--enable-fast-mutexes], [compile with fast mutexes, default: no]))
33
34 AC_MSG_CHECKING(whether to compile with fast mutexes)
35 AS_IF([test "x$enable_fast_mutexes" = "xyes"],
36 [
37 CPPFLAGS="$CPPFLAGS -DMY_PTHREAD_FASTMUTEX=1"
38 AC_MSG_RESULT(yes)
39 ],
40 [ AC_MSG_RESULT(no) ]
41 )
42])
43
44 30
45dnl Run tests using C++ compiler 31dnl Run tests using C++ compiler
46dnl AC_LANG(C++) 32dnl AC_LANG(C++)
47 33
48CHECK_DEBUG 34CHECK_DEBUG
49CHECK_FAST_MUTEXES
50 35
51#check for mysql src 36#check for mysql src
52MYSQL_SRC_TEST 37MYSQL_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], [
30 fi 30 fi
31 done 31 done
32 AC_DEFINE([MYSQL_SRC], [1], [Source directory for MySQL]) 32 AC_DEFINE([MYSQL_SRC], [1], [Source directory for MySQL])
33 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" 33 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"
34 AC_MSG_RESULT(["$ac_mysql_source_dir"]) 34 AC_MSG_RESULT(["$ac_mysql_source_dir"])
35 ], 35 ],
36 [ 36 [
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 @@
13 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 13 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
14*/ 14*/
15#include "mysql_inc.h" 15#include "mysql_inc.h"
16#include <sql_base.h>
16#include <sql_show.h> 17#include <sql_show.h>
17#include <sql_table.h> 18#include <sql_table.h>
18#include <sql_parse.h> 19#include <sql_parse.h>
19#include <sql_db.h> 20#include <sql_db.h>
21#include <auth_common.h>
20 22
21#define STR_OR_NIL(S) ((S) ? (S) : "<nil>") 23#define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
22 24
@@ -26,7 +28,7 @@ typedef struct st_lookup_field_values
26 bool wild_db_value, wild_table_value; 28 bool wild_db_value, wild_table_value;
27} LOOKUP_FIELD_VALUES; 29} LOOKUP_FIELD_VALUES;
28 30
29bool calc_lookup_values_from_cond(THD *thd, Item *cond, TABLE_LIST *table, 31bool get_lookup_field_values(THD *thd, Item *cond, TABLE_LIST *table,
30 LOOKUP_FIELD_VALUES *lookup_field_vals); 32 LOOKUP_FIELD_VALUES *lookup_field_vals);
31 33
32/*----------------------------------------------------------------------------*/ 34/*----------------------------------------------------------------------------*/
@@ -37,13 +39,13 @@ make_db_list(THD *thd, List<LEX_STRING> *db_names,
37 MEM_ROOT *tmp_mem_root) 39 MEM_ROOT *tmp_mem_root)
38{ 40{
39 /* 41 /*
40 If we have db lookup vaule we just add it to list and 42 If we have db lookup value we just add it to list and
41 exit from the function. 43 exit from the function.
42 We don't do this for database names longer than the maximum 44 We don't do this for database names longer than the maximum
43 path length. 45 path length.
44 */ 46 */
45 if (lookup_field_vals->db_value.str 47 if (lookup_field_vals->db_value.str
46 && lookup_field_vals->db_value.length < FN_REFLEN) 48 && lookup_field_vals->db_value.length <= NAME_LEN)
47 { 49 {
48 if (db_names->push_back(&lookup_field_vals->db_value)) 50 if (db_names->push_back(&lookup_field_vals->db_value))
49 return 1; 51 return 1;
@@ -62,14 +64,6 @@ struct TABLE_DATA
62 longlong size; 64 longlong size;
63}; 65};
64 66
65static char *fn_remove_ext(char *name)
66{
67 char *res = strrchr(name, '.');
68 if (res)
69 return res;
70 return name + strlen(name);
71}
72
73/* 67/*
74 SYNOPSIS 68 SYNOPSIS
75 thd thread handler 69 thd thread handler
@@ -84,35 +78,56 @@ static char *fn_remove_ext(char *name)
84 FIND_FILES_DIR no such directory, or directory can't be read 78 FIND_FILES_DIR no such directory, or directory can't be read
85*/ 79*/
86static find_files_result 80static find_files_result
87find_tables(THD *thd, List<TABLE_DATA> *tables, 81find_tables(THD *thd, List<TABLE_DATA> *tables, const char *db,
88 const char *db, const char *path, const char *wild) 82 const char *path, const char *wild, MEM_ROOT *tmp_mem_root)
89{ 83{
90 char *ext;
91 MY_DIR *dirp; 84 MY_DIR *dirp;
92 FILEINFO *file; 85 MEM_ROOT **root_ptr = NULL, *old_root = NULL;
93 uint file_name_len;
94 char uname[NAME_LEN + 1]; /* Unencoded name */
95#ifndef NO_EMBEDDED_ACCESS_CHECKS 86#ifndef NO_EMBEDDED_ACCESS_CHECKS
96 uint col_access = thd->col_access; 87 uint col_access = thd->col_access;
97#endif 88#endif
98 uint wild_length = 0; 89 size_t wild_length = 0;
99 TABLE_LIST table_list; 90 TABLE_LIST table_list;
100 TABLE_DATA *table_data = NULL; 91 TABLE_DATA *table_data = NULL;
101 DBUG_ENTER("find_files"); 92 DBUG_ENTER("find_files");
102 93
94 if (wild)
95 {
96 if (!wild[0])
97 wild = 0;
98 else
99 wild_length = strlen(wild);
100 }
101
103 memset(&table_list, 0, sizeof(table_list)); 102 memset(&table_list, 0, sizeof(table_list));
104 103
105 if (!(dirp = my_dir(path, MYF(MY_WANT_STAT)))) 104 if (!(dirp = my_dir(path, MYF(MY_WANT_STAT))))
106 { 105 {
107 if (my_errno == ENOENT) 106 if (my_errno() == ENOENT)
108 my_error(ER_BAD_DB_ERROR, MYF(ME_BELL + ME_WAITTANG), db); 107 my_error(ER_BAD_DB_ERROR, MYF(0), db);
109 else 108 else
110 my_error(ER_CANT_READ_DIR, MYF(ME_BELL + ME_WAITTANG), path, my_errno); 109 {
110 char errbuf[MYSYS_STRERROR_SIZE];
111 my_error(ER_CANT_READ_DIR, MYF(0), path,
112 my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno()));
113 }
111 DBUG_RETURN(FIND_FILES_DIR); 114 DBUG_RETURN(FIND_FILES_DIR);
112 } 115 }
113 116
114 for (uint i = 0; i < (uint)dirp->number_off_files; i++) 117 if (tmp_mem_root)
118 {
119 root_ptr = my_thread_get_THR_MALLOC();
120 old_root = *root_ptr;
121 *root_ptr = tmp_mem_root;
122 }
123
124 for (uint i = 0; i < dirp->number_off_files; i++)
115 { 125 {
126 char uname[NAME_LEN + 1]; /* Unencoded name */
127 FILEINFO *file;
128 size_t file_name_len;
129 char *ext;
130
116 file = dirp->dir_entry + i; 131 file = dirp->dir_entry + i;
117 /* skip '.', '..', db.opt and temp files. */ 132 /* skip '.', '..', db.opt and temp files. */
118 if ((file->name[0] == '.' && 133 if ((file->name[0] == '.' &&
@@ -121,15 +136,19 @@ find_tables(THD *thd, List<TABLE_DATA> *tables,
121 || is_prefix(file->name, tmp_file_prefix)) 136 || is_prefix(file->name, tmp_file_prefix))
122 continue; 137 continue;
123 138
124 ext = fn_remove_ext(file->name); 139 if ((ext = strrchr(file->name, '.')))
125 *ext = 0; 140 *ext = 0;
126 file_name_len = filename_to_tablename(file->name, uname, sizeof(uname)); 141 file_name_len = filename_to_tablename(file->name, uname, sizeof(uname));
127 142
128 if (table_data != NULL 143 if (table_data != NULL)
129 && !my_strcasecmp(files_charset_info, uname, table_data->name.str))
130 { 144 {
131 table_data->size += file->mystat->st_size; 145 if (!my_strcasecmp(files_charset_info, uname, table_data->name.str))
132 continue; 146 {
147 table_data->size += file->mystat->st_size;
148 continue;
149 }
150 else
151 table_data = NULL;
133 } 152 }
134 153
135 if (wild) 154 if (wild)
@@ -150,7 +169,7 @@ find_tables(THD *thd, List<TABLE_DATA> *tables,
150 /* Don't show tables where we don't have any privileges */ 169 /* Don't show tables where we don't have any privileges */
151 if (db && !(col_access & TABLE_ACLS)) 170 if (db && !(col_access & TABLE_ACLS))
152 { 171 {
153 table_list.db = (char*)db; 172 table_list.db = db;
154 table_list.db_length = strlen(db); 173 table_list.db_length = strlen(db);
155 table_list.table_name = uname; 174 table_list.table_name = uname;
156 table_list.table_name_length = file_name_len; 175 table_list.table_name_length = file_name_len;
@@ -162,7 +181,11 @@ find_tables(THD *thd, List<TABLE_DATA> *tables,
162 181
163 table_data = new TABLE_DATA(); 182 table_data = new TABLE_DATA();
164 table_data->size = file->mystat->st_size; 183 table_data->size = file->mystat->st_size;
165 if (!thd->make_lex_string(&table_data->name, uname, file_name_len, FALSE) 184 if (!(tmp_mem_root
185 ? make_lex_string_root(tmp_mem_root, &table_data->name, uname,
186 file_name_len, FALSE)
187 : thd->make_lex_string(&table_data->name, uname,
188 file_name_len, FALSE))
166 || tables->push_back(table_data)) 189 || tables->push_back(table_data))
167 { 190 {
168 my_dirend(dirp); 191 my_dirend(dirp);
@@ -175,23 +198,28 @@ find_tables(THD *thd, List<TABLE_DATA> *tables,
175 198
176 //(void)ha_find_files(thd, db, path, wild, dir, files); 199 //(void)ha_find_files(thd, db, path, wild, dir, files);
177 200
201 if (tmp_mem_root)
202 *root_ptr = old_root;
203
178 DBUG_RETURN(FIND_FILES_OK); 204 DBUG_RETURN(FIND_FILES_OK);
179} 205}
180 206
181static int 207static int
182make_table_list(THD *thd, List<TABLE_DATA> *table_names, LEX *lex, 208make_table_list(THD *thd, List<TABLE_DATA> *table_names, LEX *lex,
183 LEX_STRING *db_name) 209 LOOKUP_FIELD_VALUES *lookup_field_vals, LEX_STRING *db_name,
210 MEM_ROOT *tmp_mem_root)
184{ 211{
185 char path[FN_REFLEN + 1]; 212 char path[FN_REFLEN + 1];
186 build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0); 213 build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0);
187 214
188 find_files_result res = find_tables(thd, table_names, db_name->str, path, 215 find_files_result res = find_tables(thd, table_names, db_name->str, path,
189 NullS); 216 lookup_field_vals->table_value.str, tmp_mem_root);
190 if (res != FIND_FILES_OK) 217 if (res != FIND_FILES_OK)
191 { 218 {
192 /* 219 /*
193 Downgrade errors about problems with database directory to warnings. 220 Downgrade errors about problems with database directory to
194 Another thread may have dropped database, and we may still have a name 221 warnings if this is not a 'SHOW' command. Another thread
222 may have dropped database, and we may still have a name
195 for that directory. 223 for that directory.
196 */ 224 */
197 if (res == FIND_FILES_DIR) 225 if (res == FIND_FILES_DIR)
@@ -217,7 +245,7 @@ static ST_FIELD_INFO fields_info[] =
217 {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name", 245 {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Name",
218 SKIP_OPEN_TABLE}, 246 SKIP_OPEN_TABLE},
219 {"TABLE_SIZE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 247 {"TABLE_SIZE", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0,
220 (MY_I_S_MAYBE_NULL | MY_I_S_UNSIGNED), "Table_size", SKIP_OPEN_TABLE}, 248 MY_I_S_UNSIGNED, "Table_size", SKIP_OPEN_TABLE},
221 {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} 249 {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
222}; 250};
223 251
@@ -227,7 +255,7 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond)
227 TABLE *table = tables->table; 255 TABLE *table = tables->table;
228 LOOKUP_FIELD_VALUES lookup_field_vals; 256 LOOKUP_FIELD_VALUES lookup_field_vals;
229#ifndef NO_EMBEDDED_ACCESS_CHECKS 257#ifndef NO_EMBEDDED_ACCESS_CHECKS
230 Security_context *sctx = thd->security_ctx; 258 Security_context *sctx = thd->security_context();
231#endif 259#endif
232 List<LEX_STRING> db_names; 260 List<LEX_STRING> db_names;
233 List_iterator_fast<LEX_STRING> it(db_names); 261 List_iterator_fast<LEX_STRING> it(db_names);
@@ -236,27 +264,15 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond)
236 DBUG_ENTER("fill_table"); 264 DBUG_ENTER("fill_table");
237 265
238 MEM_ROOT tmp_mem_root; 266 MEM_ROOT tmp_mem_root;
239 init_sql_alloc(&tmp_mem_root, TABLE_ALLOC_BLOCK_SIZE, 0); 267 init_sql_alloc(key_memory_get_all_tables, &tmp_mem_root,
268 TABLE_ALLOC_BLOCK_SIZE, 0);
240 269
241 memset(&lookup_field_vals, 0, sizeof(LOOKUP_FIELD_VALUES)); 270 if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
242 if (calc_lookup_values_from_cond(thd, cond, tables, &lookup_field_vals))
243 { 271 {
244 error = 0; 272 error = 0;
245 goto err; 273 goto err;
246 } 274 }
247 275
248 if (lower_case_table_names)
249 {
250 /*
251 We can safely do in-place upgrades here since we are
252 allocating a new memory buffer for these strings.
253 */
254 if (lookup_field_vals.db_value.str && lookup_field_vals.db_value.str[0])
255 my_casedn_str(system_charset_info, lookup_field_vals.db_value.str);
256 if (lookup_field_vals.table_value.str && lookup_field_vals.table_value.str[0])
257 my_casedn_str(system_charset_info, lookup_field_vals.table_value.str);
258 }
259
260 DBUG_PRINT("INDEX VALUES", ("db_name='%s', table_name='%s'", 276 DBUG_PRINT("INDEX VALUES", ("db_name='%s', table_name='%s'",
261 STR_OR_NIL(lookup_field_vals.db_value.str), 277 STR_OR_NIL(lookup_field_vals.db_value.str),
262 STR_OR_NIL(lookup_field_vals.table_value.str))); 278 STR_OR_NIL(lookup_field_vals.table_value.str)));
@@ -296,19 +312,21 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond)
296 goto err; 312 goto err;
297 313
298 LEX_STRING *db_name; 314 LEX_STRING *db_name;
315 it.rewind(); /* To get access to new elements in basis list */
299 while ((db_name = it++)) 316 while ((db_name = it++))
300 { 317 {
301#ifndef NO_EMBEDDED_ACCESS_CHECKS 318#ifndef NO_EMBEDDED_ACCESS_CHECKS
302 if ((check_access(thd, SELECT_ACL, db_name->str, &thd->col_access, NULL, 0, 1) 319 if ((check_access(thd, SELECT_ACL, db_name->str, &thd->col_access, NULL, 0, 1)
303 || (!thd->col_access && check_grant_db(thd, db_name->str))) 320 || (!thd->col_access && check_grant_db(thd, db_name->str)))
304 && !sctx->master_access & (DB_ACLS | SHOW_DB_ACL) 321 && !sctx->check_access(DB_ACLS | SHOW_DB_ACL, true)
305 && !acl_get(sctx->get_host()->ptr(), sctx->get_ip()->ptr(), 322 && !acl_get(sctx->host().str, sctx->ip().str,
306 sctx->priv_user, db_name->str, 0)) 323 sctx->priv_user().str, db_name->str, 0))
307 continue; 324 continue;
308#endif 325#endif
309 326
310 List<TABLE_DATA> tables; 327 List<TABLE_DATA> tables;
311 int res = make_table_list(thd, &tables, lex, db_name); 328 int res = make_table_list(thd, &tables, lex, &lookup_field_vals,
329 db_name, &tmp_mem_root);
312 if (res) 330 if (res)
313 { 331 {
314 tables.delete_elements(); 332 tables.delete_elements();
@@ -325,8 +343,7 @@ static int fill_table(THD *thd, TABLE_LIST *tables, Item *cond)
325 system_charset_info); 343 system_charset_info);
326 table->field[1]->store(table_data->name.str, table_data->name.length, 344 table->field[1]->store(table_data->name.str, table_data->name.length,
327 system_charset_info); 345 system_charset_info);
328 table->field[2]->set_notnull(); 346 table->field[2]->store(table_data->size, TRUE);
329 table->field[2]->store((longlong) table_data->size, TRUE);
330 if (schema_table_store_record(thd, table)) 347 if (schema_table_store_record(thd, table))
331 { 348 {
332 tables.delete_elements(); 349 tables.delete_elements();
@@ -367,7 +384,7 @@ mysql_declare_plugin(table_sizes)
367 PLUGIN_LICENSE_GPL, /* license type */ 384 PLUGIN_LICENSE_GPL, /* license type */
368 init, /* init function */ 385 init, /* init function */
369 NULL, 386 NULL,
370 0x0506, /* version = 5.6 */ 387 0x0507, /* version = 5.7 */
371 NULL, /* no status variables */ 388 NULL, /* no status variables */
372 NULL, /* no system variables */ 389 NULL, /* no system variables */
373 NULL, /* no reserved information */ 390 NULL, /* no reserved information */